|
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]
|