|
Posted by frizzle on 11/07/27 11:31
David Wahler wrote:
> 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
First sorry for not quoting. I have only recently discovered the
quoting part
in Google Groups.
Second, thank you so much for your code. This is just great! I would
have
never ever thought of this! Thanks a lot!
Greetings Frizzle.
Navigation:
[Reply to this message]
|