You are here: Re: sorting query results into groups « PHP Programming Language « IT news, forums, messages
Re: sorting query results into groups

Posted by Marcin Dobrucki on 09/06/05 13:45

guitarromantic@gmail.com wrote:

> I have a 'staff' table with a column 'status', corresponding to a
> 'statuses' table with the appropriate titles (eg 1 | Editor in Chief).
> I want to display on the page the headings (the titles from statuses)
> along with all of the staff members with that status ID.
>
> I've attempted this using a query for each possible status, which I
> figure was pretty inefficient (plus it didn't work properly). The best
> I could do manually was to just display a list of staff and their
> statuses sorted in order of the title ranks.
>
> How can I do this efficiently?

How about (skipping the fetch from the db, assuming you have a result
already):

while ($row =& $res->fetchRow()) {
$staff[$row['title']][] = $row['name'];
}


This should create something like this:

array ( "Secretary" => array (0 => "Lolli Pop",
1 => "Jonsey Jones"
3 => "Bob Bored"),
"Editor in Chief" => array (0 => "Big Fish",
1 => "Jack Sardine"),
...);

Well, you catch the drift.

/Marcin

 

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

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