欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

两个设置分页的都出有关问题,想屎了.

程序员文章站 2024-01-20 17:59:04
...
两个设置分页的都出问题,想屎了...

$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 {
echo $separator;
buildLink("$start-$end", $start);
}

$end = ($total > $start) ? "$total":"";
echo $separator;
buildLink("$start-$end", $start);
}




?>


另一种思路的.....

$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 {
echo " Next Page
";
}
if($cur > 0)
{
echo " Prev Page
";

}


?>


问题如下:每次点击下一页,或者上一页,显示的都是同样的内容,即首页内容。 当数据表的内容有3000行...是怎么回事啊?
------解决方案--------------------
42 行有 ...setPage02.php?offset=$i'>$i....
而第 2 行是 $offset = isset($_GET['ofset']) ? intval($_GET['offset']) : 1;

知道问题在哪了吧?
两个设置分页的都出有关问题,想屎了.

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频