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

Posted by Tyrone Slothrop on 10/05/78 11:33

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. ;-)

 

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

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