Reply to Re: Formatting output from database

Your name:

Reply:


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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация