Page 1 of 1

how to customize this ?

Posted: Sun Jun 24, 2007 11:49 pm
by PHPycho
Hello forums !!
I am not getting the solution for the following case:
My query results gives the following results:
--------------------
| field1 | field 2 |
---------------------
| name1 | value1 |
| name1 | value2 |
| name1 | value3 |
| name2 | value4 |
| name2 | value5 |
:
:
etc.

Code: Select all

while($row = ..){
	//show results  here..
}
I would like to show the results as:
name1
-value1
-value2
-value3

name2
-value4
-value5
without displaying like
name1
-vaue1
name1
-value2
name1
-value3 etc..
Please help me in this case..
Thanks in advance to all of you

Posted: Mon Jun 25, 2007 12:13 am
by feyd
Read through the first two links of Useful Posts.

Please try to be a bit more specific in topic titles next time.

Posted: Mon Jun 25, 2007 12:14 am
by Benjamin

Code: Select all

<pre>
<?php

$data = array();

$data['item1'] = range('a', 'f');
$data['item2'] = range('g', 'm');

foreach ($data as $parent => $children)
{
    echo "$parent\n";
    foreach ($children as $child)
    {
        echo " -$child\n";
    }
}
Outputs:

Code: Select all

item1
 -a
 -b
 -c
 -d
 -e
 -f
item2
 -g
 -h
 -i
 -j
 -k
 -l
 -m

Posted: Mon Jun 25, 2007 5:14 am
by superdezign
Maybe you'd be interested in GROUP BY and GROUP_CONCAT() in MySQL.