There is a problem with the two settings.

Source: Internet
Author: User
Two sets of paging problems, think of it... & lt ;? Php $ offset & nbsp; isset ($ _ GET [pid])? Intval ($ _ GET [pid]): 1; if (! $ Offset) & nbsp; $ offset & nbsp; 1; $ perpage & nbsp; 50; $ db & nbsp; NEW & nbsp; two sets of paging problems, think of it...

$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 idea .....

$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 the next page or the previous page, the same content is displayed, that is, the homepage content. When there are 3000 rows in the data table, why?
------ Solution --------------------
42 rows have... setPage02.php? Offset = $ I '> $ I ....
And the 2nd rows are $ offset = isset ($ _ GET ['ofset'])? Intval ($ _ GET ['offset']): 1;

Do you know where the problem is?

Related Article

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.