Two settings paging is a problem, think of excrement ...
$offset = isset ($_get[' pid ")? Intval ($_get[' pid"): 1;
if (! $offset) $offset = 1;
$perpage = 50;
$db = NEW PDO ("Mysql:host=localhost; Port = 3306; dbname =library ", ' Root ', ' cai123 ');
$total = $db->query (' SELECT COUNT (*) from Library.messages ')->fetchcolumn (0);
$sql = ' select * from Library.messages '. " LIMIT $perpage OFFSET ". ($offset-1);
$result = $db->query ($sql);
if ($result)
{
foreach ($result->fetchall () as $row)
{
echo "Subject:". $row [5]. "
";
}
}
Else
{
$error = $db->errorinfo ();
echo "Error happened ...". $error [2];
Exit ();
}
Buildindex ($perpage, $total);//1,50,3500
/////////////////////////////////////////////////////////////////
function Buildlink ($index, $offset)
{
echo "$index";
}
function Buildindex ($perpage, $total)
{
$separator = ' | ';
Buildlink ($offset ==1, ' <
for ($start = 1, $end = $perpage; $end < $total; $start + = $perpage, $end + = $perpage)
{
Echo $separator;
Buildlink ("$start-$end", $start);
}
$end = ($total > $start)? "$total": "";
Echo $separator;
Buildlink ("$start-$end", $start);
}
?>
Another way of thinking .....
$offset = isset ($_get[' pid ")? Intval ($_get[' pid"): 1;
if (! $offset) $offset = 1;
$perpage = 50;
$db = NEW PDO ("Mysql:host=localhost; Port = 3306; dbname =library ", ' Root ', ' cai123 ');
$total = $db->query (' SELECT COUNT (*) from Library.messages ')->fetchcolumn (0);
$sql = ' SELECT * from Library.messages LIMIT '. ($offset-1) * $perpage. ", $perpage";
$result = $db->query ($sql);
if ($result)
{
foreach ($result->fetchall () as $row)
{
echo "Subject: ". $row [5]. "
";
}
}
Else
{
$error = $db->errorinfo ();
echo "Error happened ...". $error [2];
Exit ();
}
$numpage = $total% $perpage;
if ($total% $perpage) $numpage + +;
$cur = $offset;
if ($cur < $numpage)
{
echo "Next page
";
}
if ($cur > 0)
{
echo "Prev page
";
}
?>
The problem is as follows: Each time you click on the next page, or the previous page, the same content is displayed, that is, the homepage content. When the contents of the data table have 3000 rows ... What's going on here?
------Solution--------------------
42 lines have ... setpage02.php? Offset= $i ' > $i ....
and line 2nd is $offset = isset ($_get[' Ofset']) ? Intval ($_get[' offset '): 1;
You know where the problem is?