【发布时间】:2017-02-20 13:02:39
【问题描述】:
我在互联网上关注一些使用 ODBC 进行 PHP 分页的示例,并根据我自己的使用进行更改。
我设法使NEXT 和PREVIOUS 工作。单击NEXT 或PREVIOUS 时,页面的URL 会发生变化。例如,当我点击 NEXT 时,这是 URL localhost/mypage.php?page=2。
这里的问题是数据表不会显示。
这是我的代码:
function inv_rows($r1)
{
ob_start();
(int)$number = odbc_result_all($r1);
ob_clean();
return $number;
}
$page = isset($_GET["page"]) ? $_GET["page"] : 1;
if(empty($page)){$page = 1;
}
$query = "SELECT UserId, UserNm FROM User";
$num_result = odbc_exec($db, $query);
$numrows = inv_rows($num_result);
$limit = 10;
$offset = ($page - 1) * $limit;
$sql = odbc_exec($conn,"SELECT UserId, UserNm FROM User LIMIT $limit OFFSET $offset");
$result = odbc_exec($db, $sql);
echo "<table style='width: 600;'>";
while(odbc_fetch_row($result))
{
echo "<tr>
<td style='width: 300; height: 15px;>";
echo odbc_result_all($result, "UserId");
echo "</td>
<td style='width: 300; height: 15px;'>";
echo odbc_result_all($result, "UserNm");
echo "</td>
</tr>";
}
echo "</table>";
if($page !=1)
{
$pageprev = $page - 1;
echo "<a href='paging2.php?page=$pageprev' style='text-decoration: none'> PREVIOUS </a>";
}
else
{
echo " PREVIOUS ";
}
if(($numrows - ($limit * $page)) > 0)
{
$pagenext = $page + 1;
echo "<a href='paging2.php?page=$pagenext' style='text-decoration: none'>NEXT</a>"; }
else
{
echo " NEXT ";
}
odbc_free_result($result);
exit;
?>
我确定我错过了什么。请指导我。谢谢。
【问题讨论】:
-
this SO 问题的可能重复项。