Jump to content


Photo

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


  • Please log in to reply
2 replies to this topic

#1 Russia

Russia

    Advanced Member

  • Members
  • PipPipPip
  • 420 posts

Posted 02 July 2013 - 11:53 AM

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



#2 mac_gyver

mac_gyver

    Advanced Member

  • Administrators
  • 2,707 posts

Posted 02 July 2013 - 12:25 PM

http://dev.mysql.com...function_concat


multi-purpose programming fool. well written source-code should be self-documenting. well written code should be self-troubleshooting. 


#3 Russia

Russia

    Advanced Member

  • Members
  • PipPipPip
  • 420 posts

Posted 02 July 2013 - 08:42 PM

 

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






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com