table slabpay
-------------------------------------------------------
agent_id|agent_name|cust_id|cust_name|installment_amt|
-------------------------------------------------------
1       |mike      |1      |john     |350         |
-------------------------------------------------------
1       |mike      |1      |john     |400         |
------------------------------------------------------
1       |mike      |2      |abraham  |350         |
-------------------------------------------------------
1       |mike      |1      |john     |450         |
-------------------------------------------------------
1       |mike      |2      |abraham  |400         |
-------------------------------------------------------

mysql query
------------------------------------------------------


`$select = mysql_query("SELECT cust_id, cust_name,installment_amt FROM slabpay WHERE agent_id=1");`



result should be
------------------------------------------------------
cust_id          | installment_amt         
-------------------------------------------------------
1,john           ,350,400,450
2,abraham        ,350,400
------------------------------------------------------

i am new to php mysql please help me to solve this problem

SELECT cust_id, cust_name, GROUP_CONCAT(installment_amt)
FROM slabpay
WHERE agent_id = 1
GROUP BY cust_id

i am using following code

$select = mysql_query("SELECT cust_id, cust_name, GROUP_CONCAT(installment_amt SEPARATOR ',') as installamt FROM slabpay  WHERE agent_id=1 GROUP BY cust_id");
while($row1 = mysql_fetch_assoc($select)){
$installamt = $row1['installamt'];
echo $installamt;

Getting Output Result:
350,400,450350,400

there should be a line break after 450 like
350,400,450
350,400

the values 350,400 are abraham's

Member Avatar for diafol
while($row1 = mysql_fetch_assoc($select))
{
    $installamt = $row1['installamt'];
    echo $installamt . '<br />';
    ...
}

once again thanks diafol

how to convert the values of $installment to arrays line by line?

Member Avatar for diafol

If comma separated:

while(...))
{
    $arr = explode(",",$installment);
}

That will place all the comma separated values into an array for you, so you can use a foreach() loop to format, or even an implode(). However, you have many many options, including preg_replace or str_replace - where you could replace the comma for anything you want.

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.