Russia Posted July 2, 2013 Share Posted July 2, 2013 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: Right now I have it as: 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 https://forums.phpfreaks.com/topic/279797-exporting-csv-want-to-combine-2-columns-into-one-with-a-comma-in-the-middle/ Share on other sites More sharing options...
mac_gyver Posted July 2, 2013 Share Posted July 2, 2013 http://dev.mysql.com/doc/refman/5.6/en/string-functions.html#function_concat Link to comment https://forums.phpfreaks.com/topic/279797-exporting-csv-want-to-combine-2-columns-into-one-with-a-comma-in-the-middle/#findComment-1439091 Share on other sites More sharing options...
Russia Posted July 3, 2013 Author Share Posted July 3, 2013 http://dev.mysql.com/doc/refman/5.6/en/string-functions.html#function_concat 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 https://forums.phpfreaks.com/topic/279797-exporting-csv-want-to-combine-2-columns-into-one-with-a-comma-in-the-middle/#findComment-1439177 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.