* Thus wrote Chris Lott:
> On Sat, 13 Nov 2004 06:30:14 +0000, Curt Zirzow
> <[EMAIL PROTECTED]> wrote:
>
> > > You might normalize the data a bit.
> >
> > agreed!
> >
> > Curt
>
> My data IS Normalized! The results you are seeing below are from
> joining together the books, subjects, and books_subjects xref table,
> as I explained below. But my point is that because the data is
> normalized, I end up with a result set that shows one row per subject,
> making aggregate display of the subjects (so they appear as one set
> for the user) painful...
oops, i was kind of quick to jump to that decision without reading
everyting...
>
> Thus the tables and query I posted:
>
> The query and tables are simple:
>
> select books.id, books.title, subjects.subject
> from books, subjects, books_subjects
> where books_subjects.bid = books.id
> and books_subjects.sid = subjects.id
The GROUP_CONCAT() tool, mentioned earlier does seem like a decent
solution unless you plain on writing sql code that is portable.
If the latter is true, then you can aggregate the data within php
with something like:
$id = 0; //assuming no id can be zero
$subjects = '';
while ($row = mysql_fetch_assoc($result_handle) ) {
if ($id && $id != $row['id'] ) {
echo "id: {$row['id']}<br>";
echo "title: {$row['title']}<br>";
echo "Subjects: {$subjects}<br>";
$subjects = ''; // reset
}
$subjects .= $row['subject'] . ',';
$id = $row['id'];
}
// and echo last item here as well.
Curt
--
Quoth the Raven, "Nevermore."
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php