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" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]