Two settings paging all out about the problem, thinking crap.

Source: Internet
Author: User
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?
  • 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.