0
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

3
Contributors
5
Replies
23
Views
4 Years
Discussion Span
Last Post by diafol
0
SELECT cust_id, cust_name, GROUP_CONCAT(installment_amt)
FROM slabpay
WHERE agent_id = 1
GROUP BY cust_id
0

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

Edited by blueguy777: to remove extra variable

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

once again thanks diafol

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

Edited by blueguy777: forgot to include 1 more word

0

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.

This question has already been answered. 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.