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

Link to comment
Share on other sites

 

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
');



			
		
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.