You are here: Re: help with query and presentation... « PHP SQL « IT news, forums, messages
Re: help with query and presentation...

Posted by Frank on 12/04/05 03:44

On Fri, 02 Dec 2005 17:42:58 -0800, Tyrone Slothrop <ts@paranoids.com>
wrote:

>On Fri, 02 Dec 2005 16:46:14 -0600, Frank <noreply@nospam> wrote:
>
>>
>>I have a mySql db table with the following structure:
>>
>>main_category| category| sub_category| answer|date
>>
>>Basically, the data will be along these lines:
>>Neuro | LOC | Status | answer1|date
>>Neuro | LOC | Status | answer2|date
>>Neuro | LOC | Status | answer3|date
>>Senso| Visi | Clarity | answer1|date
>>Senso| Visi | Clarity | answer2|date
>>etc...
>>I am trying to query the db and create labels in order to present the
>>user with the data in the following structure:
>>
>>Main Category
>> Category
>> Sub Category
>> answer1
>> answer2
>> answer3
>> ...
>>
>>Main Category
>> Category
>> Etc...
>>
>>I could really use some help on a query to group the data in this way!
>>
>>Thanks in advance!!!
>>
>>
>>Frank
>
>You could run multiple queries to do group by's or you can run one
>query and be creative.
>
>$ctgy = '';
>$sctgy = '';
>$qy = "SELECT * FROM table order by main_category, category";
>$rs = mysql_query ($qy) or die (mysql_error());
>while ($r = mysql_fetch_array ($rs)) {
> if ($ctgy != $r['main_category']) {
> $ctgy = $r['main_category'];
> echo "<div style='padding-left:10px;">$ctgy</div>";
> }
> // do the same thing for the sctgy with padding-left:20px;
> // then display your answers
> echo "<div style='padding-left:30px;'>{$r['answer1']}</div>";
> //etc.
> }
>
>Warning: this code has not been tested for errors. ;-)

Tyrone,

Thanks very much for the help, but I am not quite sure that I
understand. in the if ($ctgy!=..) statement, what I am testing
against? I don't see where $ctgy is ever set to anything but an emptly
string.
In my web app there will literally be over 100 main categories, cats,
and sub-cats each with a several answers. So, I am trying to make this
as dynamic as possible. Could you explain a little more for my feeble
mind. Also, could you show me you logic for running multiple queries
on this.

Thanks!!!!!!

Frank

 

Navigation:

[Reply to this 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

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