how to group entries from two tables like publishers and books? (pub is header)

From: Date: Mon, 20 Dec 2004 21:03:37 +0000
Subject: how to group entries from two tables like publishers and books? (pub is header)
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-16350@lists.php.net to get a copy of this message
I want to query and display the groupings like this: HTML Code: Publishers 1 Book 1 Book 2 Book 3 Book 4Publisher 2 Book 5 Book 6Publisher 3 Book 91 It seems to be I could query the publishers once. In the loop to write the html, I could query the books giving the pub ID every time but that would be inefficient. I could query once: SELECT pub.ID, book.ID, pub.name, book.ISBN FROM pub inner join book on pub.ID=book.pub_ID which would give me : Publishers 1 Book 1 Publishers 1 Book 2 Publishers 1 Book 3 Publishers 1 Book 4 Publishers 2 Book 5 Publishers 3 Book 6 Then how would I formet that to look I want? Any ideas? - thanks! One suggestion on another board was to do this (below) but I can't get it to work with PEAR:DB: $cursor = ''; while($row = mysql_fetch_array($res, MYSQL_ASSOC)) { if($row['name'] != $cursor) { print("{$row['name']}<br />\n"); } print("{$row['ISBN']}<br />\n"); $cursor = $row['name']; } --------------------------------- Do you Yahoo!? Jazz up your holiday email with celebrity designs. Learn more.

« previous php.pear.general (#16350) next »