PHP Tutorial previous article with Next post code
Basic knowledge:
is to sort the ID pair by the ORDER by id DESC or the ORDER by ID ASC, and then to determine the current id> or less than the current article ID.
The SQL statements for the instance are as follows:
SELECT * FROM news where id< $id order by id DESC limit 0,1
SELECT * FROM news where id> $id 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, ' The pioneer of Deng '),
(2, ' The pioneer of Deng '),
(5, ' Fdafdsaf '),
(6, ' www.bKjia.c0m ');
All right, let's take a look at 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 post
$sql 1 = "SELECT * from String_find where id< $cid ORDER by ID ASC limit 0,1";//Next post
$result = mysql_query ($sql);
if (mysql_num_rows ($result))
{
$rs = Mysql_fetch_array ($result);
echo "Previous". $rs [0];
}
Else
{
echo "is Gone";
}
$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 "is Gone";
}
This site original article reproduced annotated from www.bKjia.c0m
http://www.bkjia.com/PHPjc/631999.html www.bkjia.com true http://www.bkjia.com/PHPjc/631999.html techarticle PHP Tutorial Previous with the next article Code basics: is to order by ID of the ID of DESC or ORDER by ID ASC to sort, and then judge than the current ID or less than the current article ID ...