|
Posted by David Wahler on 11/07/81 11:31
frizzle wrote:
> Your first example is what i have right now, and the result of the
> second one
> is what i want, only, if i get this right, this would mean i'll have to
> run a
> separate query for each category...
> I'm kind of trying to avoid that ..
> Is it possible?
On Usenet, it's frowned upon to reply without quoting the previous
poster.
Running a new query for each category gets inefficient as soon as you
have more than a few categories. Why not just do this:
$result = mysql_query("SELECT c.category, l.url " .
"FROM categories c, links l " .
"WHERE l.cat_id = c.id ORDER BY category;");
$previous_category = null;
while ($row = mysql_fetch_array($result)) {
if ($row['category'] != $previous_category) {
echo "<h1>" . $row['category'] . "</h1>\n";
$previous_category = $row['category'];
}
echo $row['url'] . "<br>";
}
This allows the database to retrieve the data all at once, without
reconnecting each time.
-- David
Navigation:
[Reply to this message]
|