This article is an example of how PHP gets the article. Share to everyone for your reference. Here's how:
Today found a station problem, is directly to the latest release of the 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 ID, I want to use ORDER by ID ASC to get the sort should be, 4, good principle is so simple.
SQL implementation method, the code is as follows:
:
The code is 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:
The code is as follows:/*
int $tag 0
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 "<a href=" ". $rs [' S_url ']." " > ". $rs [' title ']." </a> ";
}
Else
{
Return ' no ';
}
}
How PHP Gets the previous page and next page of the article