PHP gets the article previous page and next page method,
This article explains how PHP gets the previous page and the next page of the article. Share to everyone for your reference. Here's how:
Today found a station of the previous page and the next page, there is no problem but the next page is directly to the latest published articles on this channel, according to the principle should be the ID of the article itself before and after the ID is the next page, let me tell you in detail.
Let's look at an example: 1,2,3,4,5.
If the above 5 is the ID, I want to sort the previous page directly using the ORDER by id DESC, such as my current ID is 3 then out of 2 is right, on the next page we want to use the order by ID ASC to get the sort should be, 4, good principle is so simple.
SQL implementation method, the code is as follows:
Previous: copy code code as follows: $sql = "select field from table name where id<3 ORDER BY id desc limit 1";
Next: Copy the code code as follows: $sql = "select field from table name where ID>3 ORDER by ID ASC limit 1";
The results are the same as we thought, okay. Finally, I will share my previous function with you, the code is as follows:
Copy the Code Code as follows:/*
Previous page, next page
int $tag 0 prev, 1 next
int $fid
*/
function Nextpre ($tag =0, $zid, $fid)
{
if ($tag)
{
$sql = "Select field from table name where id< $fid order BY id desc limit 1";
}
Else
{
$sql = "Select field from table name where id> $FID ORDER by ID ASC limit 1";
}
$sql = "SELECT * from table name where ORDER BY id desc limit 0,10";
$result = mysql_query ($sql) or Die (' query error ');
if (mysql_num_rows ($result))
{
$rs = Mysql_fetch_array ($result);
Return "". $rs [' title ']. "";
}
Else
{
Return ' no ';
}
}
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/920627.html www.bkjia.com true http://www.bkjia.com/PHPjc/920627.html techarticle PHP Gets the previous page and the next page of the article method, this article describes how PHP gets the article previous page and next page method. Share to everyone for your reference. The specific method is as follows: Today hair ...