这是我用来分页的脚本,数据限制为4但是没有出现分页链接
<?
require_once ('Pager/Pager.php');
$connection = mysql_connect( "localhost" , "root" , "" );
mysql_select_db( "ssit",$connection);
$result=mysql_query("SELECT dFrindName FROM tbl_friendslist", $connection);
$row = mysql_fetch_array($result);
$totalItems = $row['total'];
$pager_options = array(
'mode' => 'Sliding', // Sliding or Jumping mode. See below.
'perPage' => 4, // Total rows to show per page
'delta' => 4, // See below
'totalItems' => $totalItems,
);
$pager = Pager::factory($pager_options);
echo $pager->links;
list($from, $to) = $pager->getOffsetByPageId();
$from = $from - 1;
$perPage = $pager_options['perPage'];
$result = mysql_query("SELECT * FROM tbl_friendslist LIMIT 5 , $perPage",$connection);
while($row = mysql_fetch_array($result))
{
echo $row['dFrindName'].'</br>';
}
?>
答案 0 :(得分:1)
您正在使用的查询未定义total
。尝试:
$result=mysql_query("SELECT dFrindName, COUNT(dFrindName) AS total FROM tbl_friendslist GROUP BY dFrindName", $connection);
答案 1 :(得分:1)
由于您不在循环中使用mysql_fetch_array
,因此您只需获取最新的数据集。我认为你必须使用mysql_num_rows
作为总值:
...
$result=mysql_query("SELECT dFrindName FROM tbl_friendslist", $connection);
$totalItems = mysql_num_rows($result);
...