Jump to content

Exporting csv, want to combine 2 columns into one with a comma in the middle


Russia

Recommended Posts

Hey guys, how would I combine 2 columns into one specifically the first and last name? so its wellens, brian in one box.
Like this: gfURMCf.png

Right now I have it as:

67h0Uzu.png

This is the code I am using



<?php
 
include_once "config.php";
 
$result = mysql_query('
    SELECT
        pat_id AS `ID`,
        pat_lname as `Last Name`,
        pat_fname as `First Name`,
        pat_date as `IME Date`,
        office_name as `Location`,
        ins_name as `Insurance Company`,
        pat_show as `Show(Y/N)`
    FROM patients
    INNER JOIN offices ON office_id = pat_loc
    INNER JOIN insurance ON ins_id = pat_ins
');

$csv_output = '';
$headersPrinted = false;
while ($patient = mysql_fetch_assoc($result))
{
    if (!$headersPrinted)
    {
        $csv_output .= implode(',', array_keys($patient))."\n";
        $headersPrinted = true;
    }

    $csv_output .= implode(',', array_values($patient))."\n";
}
 
$filename = $file . "_" . date("d-m-Y_H-i", time());
 
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header("Content-disposition: filename=" . $filename . ".csv");
 
print $csv_output;
exit;

?>


except do not know how to combine 2 parts into one, the line 8 and line 9

 

I appreciate the help, I have added the code to this query but it throws off errors:

$result = mysql_query('
SELECT
    pat_id AS `ID`,
    concat(pat_lname, ', ', pat_fname) as `Full Name`,
    pat_date as `IME Date`,
    office_name as `Location`,
    ins_name as `Insurance Company`,
    pat_show as `Show(Y/N)`
FROM patients
INNER JOIN offices ON office_id = pat_loc
INNER JOIN insurance ON ins_id = pat_ins
');



			
		

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.