|
Posted by Rik on 03/16/07 16:33
On Fri, 16 Mar 2007 17:13:06 +0100, J.O. Aho <user@example.net> wrote:
> Nosferatum wrote:
>> I wonder how to format the output from my db. I retrive the data fine=
,
>> but each post belong to a category (total 4 categories), and I would
>> like to have the output sorted under each category in a nice manner,
>> like this:
>>
>> CATEGORY - NAME
>> post 1 data...
>> post 2 data ...
>>
>> (space)
>>
>> CATEGORY -NAME2
>> post 1 data...
>> post 2 data.. etc.
>>
>> I just don't know how to do it. Help?
>
> There are different options here, you could make 4 queries, one for ea=
ch
> category. Another way is to have one query and you store each category=
=
> to an
> array (you can also put those together in a multidimentional array) an=
d =
> then
> loop throw each array when you want to generate the output.
Also a possibility:
$query =3D 'SELECT category,post,data FROM table ORDER BY catagory';
$cat =3D '';
$result =3D mysql_query($query);
if($result){
while($row =3D mysql_fetch_assoc($result)){
if($row['category']!=3D$cat){
$cat =3D $row['category'];
echo "CATEGORY - {$cat}";
}
echo $row['post'],$row['data'];
}
}
-- =
Rik Wasmus
Navigation:
[Reply to this message]
|