0

how to convert install_amt to comma delimited array

$select = mysql_query("SELECT ac_no,cust_name,install_amt,GROUP_CONCAT(install_amt) FROM ankali_slabpay  WHERE agent_id=$agent_id GROUP BY ac_no");
    $a=array();
    while($row1 = mysql_fetch_assoc($select)){
    $installment = $row1['GROUP_CONCAT(install_amt)'];
    $a=explode(",",$installamt);
3
Contributors
6
Replies
24
Views
4 Years
Discussion Span
Last Post by diafol
0

Your code is almost right. Use an ALIAS in the SQL to help with the processing...

$select = mysql_query("SELECT ac_no,cust_name,install_amt,GROUP_CONCAT(install_amt) AS grp FROM ankali_slabpay  WHERE agent_id=$agent_id GROUP BY ac_no");
$a=array();
while($row1 = mysql_fetch_assoc($select)){
$grp = $row1['grp'];
$a=explode(",",$grp);
0

The GROUP_CONCAT() is really nifty. You can set order of items and decide on your own separator, e.g.

SELECT GROUP_CONCAT(field1 ORDER BY field1 DESC SEPARATOR '<br />') AS grp FROM table1 GROUP BY field5

However, as minitauros states, it may be better to do this in the loop. I tend to shy away from too much phaffing around with SQL.

Edited by diafol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.