You are here: Re: Categorised Links (mysql) « PHP Programming Language « IT news, forums, messages
Re: Categorised Links (mysql)

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация