Reply to Re: [PHP] mysql query

Your name:

Reply:


Posted by Richard Lynch on 02/18/05 19:34

Sebastian wrote:
> Hello,
> im working on an article system and looking to avoid running three
> queries.
> example, i have this query:
>
> SELECT id,title FROM articles WHERE id=$_GET[id]
>
> now say $_GET[id] = 5
>
> I would like to get the previous id 4 and the next id 6 (if there is one)
> so i can do something like:

You really shouldn't rely on an auto_increment 'id' field for your
prev/next article linking... Particularly as you might need to delete
articles some day.

Better to have an explicit "rank" you can set so you can organize your
articles in the order you like.

Or to have a "whatdate" time-stamp to organize them by the date they were
published.

Or... anything EXCEPT relying on consequtive auto_increment 'id's

> << Previous Article [Title]
> Next Article [Ttitle] >>
>
> i would assume this is impossible without running mulitple queries? just
> thought i'd ask in case i am wrong. i am using mysql 4x

I would just go ahead and run the 3 queries.

If you have designed your database properly, they will not be that much
more expensive than your single query, because it's a very simple query
and you only run the 3 queries once on a page.

Benchmark it and see -- You're probably worrying about micro-seconds when
you shouldn't.

--
Like Music?
http://l-i-e.com/artists.htm

[Back to original 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

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