Basic knowledge:
is to sort the ID pair with an ORDER by id DESC or an ordered by ID ASC, and then to judge the current id> or less than the current article ID
The SQL statement for the instance is as follows:
SELECT * FROM news where id< $id the ORDER by id DESC limit 0,1
SELECT * FROM news where id> $id the ORDER by id DESC limit 0,1
--
--The structure of the table ' String_find '
--
CREATE TABLE IF not EXISTS ' String_find ' (
' ID ' int (4) not NULL auto_increment,
' charList ' varchar default NULL,
PRIMARY KEY (' id ')
) Engine=myisam DEFAULT Charset=utf8 auto_increment=7;
--
--Export the data in the table ' String_find '
--
INSERT into ' string_find ' (' id ', ' charList ') VALUES
(1, ' Deng Pioneer '),
(2, ' Deng Pioneer '),
(5, ' Fdafdsaf '),
(6, ' www.111cn.net ');
All right, let's see how it's done.
*/
MySQL tutorial _pconnect (' localhost ', ' root ', ' root ') or Die (Mysql_error ());
mysql_select_db (' cc ');
mysql_query ("Set names ' GBK '");
$cid =5;//is the number of your current article
$sql = "SELECT * from String_find where id> $cid the ORDER by id DESC limit 0,1"; Previous article
$sql 1 = "SELECT * from String_find where id< $cid the ORDER by ID ASC limit 0,1";//Next article
$result = mysql_query ($sql);
if (mysql_num_rows ($result))
{
$rs = Mysql_fetch_array ($result);
echo "Previous". $rs [0];
}
Else
{
echo "No";
}
$result 1 = mysql_query ($sql 1);
if (mysql_num_rows ($result 1))
{
$rs 1 = mysql_fetch_array ($result 1);
echo "Next". $rs 1[0];
}
Else
{
echo "No";
}
This site original article reproduced annotated from Www.111cn.net