This topic is locked

Forming CSV using MYSQL GROUP_CONCAT

5/5/2012 10:55:07 AM
PHPRunner Tips and Tricks
A
acpan author

I need to form a CSV value in Php by joining the data returned from a table:
eg.
id, name, tel

1 john 812121212

2 may 213213333

3 alice 321321321
To join the tel into CSV: "812121212,213213333,321321321"
I can use php to loop through the return SQL value as usual.
But one other way is to use a single SQL command with mysql group_Contcat command.
$strSQL = "Select GROUP_CONCAT(tel ORDER BY tel DESC SEPARATOR ',' ) as csv_data

from address_book_cat ";
$rs_select_all_own = db_query($strSQL,$conn);

$data_select_all_own = db_fetch_array($rs_select_all_own);

$v_phonebook_own_csv_temp = $data_select_all_own["csv_data"];
the result is: $v_phonebook_own_csv_temp = "812121212,213213333,321321321"