How do I combine 2 MySql fields in one?

How do I combine 2 MySql fields in one?

JimBobUKIIJimBobUKII Posts: 13Questions: 1Answers: 0
edited January 2022 in Free community support

Hi,

I am using server-side script and was wondering how to combine to fields in one?. I put together the below and was looking to return both first and last name to a cell in datatables table. Is this how you would do it? If so it doesnt work for me? SOme users do not have a first or last name entered in the database
@allan you helped me before so adding you again :smiley:

$columns = array(
    array( 
       'db' => 'first_name', 
       'db' => 'last_name'
       'dt' => 0 ),
        'formatter' => function( $d, $row ) {
            return $row['first_name'].' '.$row['last_name'];
        }
    ),
    array( 'db' => 'position',   'dt' => 2 ),
    array( 'db' => 'office',     'dt' => 3 ),
    array(
        'db'        => 'start_date',
        'dt'        => 4,
        'formatter' => function( $d, $row ) {
            return date( 'jS M y', strtotime($d));
        }
    ),
    array(
        'db'        => 'salary',
        'dt'        => 5,
        'formatter' => function( $d, $row ) {
            return '$'.number_format($d);
        }
    )
);

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    One client-side approach would be to send the data as it is, and merge cells on the client within columns.render, see this example here.

    Colin

  • JimBobUKIIJimBobUKII Posts: 13Questions: 1Answers: 0

    @colin , I havent forgot!

    Little busy at the moment, I will get back to you soon! Thanks for your reply

Sign In or Register to comment.