Re: Get the previous or next id

From: Date: Thu, 23 Aug 2001 15:23:44 +0000
Subject: Re: Get the previous or next id
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-11721@lists.php.net to get a copy of this message
list($prev_id)=mysql_fetch_array(mysql_query("SELECT news_id FROM newsTable WHERE news_id<$current_id LIMIT 1;")); list($next_id)=mysql_fetch_array(mysql_query("SELECT news_id FROM newsTable WHERE news_id>$current_id LIMIT 1;")); if (!$next_id) { // no next id // kldjlsjkdf } But keep in mind that it is better to get result_id of mysql_query in a variable which eventually can be used to free (mysql_free_result($res)) instead of giving it directly ot mysql_fetch_array(); Also it is good idea after mysql_query to check if ($res){ .... } else {//error with the db } Andrey Hristov IcyGEN Corporation http://www.icygen.com 99% ----- Original Message ----- From: "Denny Suvanto" <suv11@yahoo.com> To: <php-db@lists.php.net> Sent: Thursday, August 23, 2001 6:04 PM Subject: [PHP-DB] Get the previous or next id > Hi all, > > I just built a news database for my site. > I want to give the visitor ability to browse my news > database. Problem is how to determine the next or > previous news id for the current news she is reading, > so I can give link(s), such as "<a > href="news.php?id=$prev_id">PREVIOUS</a>" and/or "<a > href="news.php?id=$next_id">NEXT</a>" if there is any. > I'm using MYSQL for the database. Can anyone give me a > suggestion? Thank you. > > Andy Wijaya > www.mediahostnet.com > > > > ____________________________________________________________ > Do You Yahoo!? > Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk > or your free @yahoo.ie address at http://mail.yahoo.ie > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.db (#11721) next »