PHP Previous and Next article Code _php Tutorial

Source: Internet
Author: User
Tags mysql tutorial
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.