PHP和MySQL分页

PHP和MySQL分页,第1张

PHP和MySQL分页

这是一个不错的起点

<?php// insert your mysql connection pre here$perPage = 10;$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;$startAt = $perPage * ($page - 1);$query = "SELECt COUNT(*) as total FROM redirectWHERe user_id = '".$_SESSION['user_id']."'";$r = mysql_fetch_assoc(mysql_query($query));$totalPages = ceil($r['total'] / $perPage);$links = "";for ($i = 1; $i <= $totalPages; $i++) {  $links .= ($i != $page )  ? "<a href='index.php?page=$i'>Page $i</a> " : "$page ";}$r = mysql_query($query);$query = "SELECt * FROM 'redirect'WHERe 'user_id'= ''.$_SESSION['user_id'].' ' ORDER BY 'timestamp' LIMIT $startAt, $perPage";$r = mysql_query($query);// display results here the way you wantecho $links; // show links to other pages


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5042852.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-15
下一篇 2022-11-15

发表评论

登录后才能评论

评论列表(0条)

保存