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

What are the contents of install_amt?

Member Avatar for diafol

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

thanks diafol it's working, how to add new line after each row

how to put new line for each row in GROUP_CONCAT(install_amt)

What about executing echo '<br>'; in each loop execution?

Member Avatar for diafol

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.