Heim > Artikel > Backend-Entwicklung > php,混编,数据分页
连接数据库
$conn = mysql_connect('localhost', 'root', 'root') or die('ErrorCode:' . mysql_errno() . ',Error:' . mysql_error());
mysql_select_db('company') or die('ErrorCode:' . mysql_errno() . ',Error:' . mysql_error());
?>
混编数据分页
$pagesize = 10;
mysql_query("SET NAMES utf8");
$sql = "SELECT count(*) cnt FROM com_info";//取出总的记录条数
$r = mysql_query($sql) or die('error code:' . mysql_errno() . ',error:' . mysql_error());
$row = mysql_fetch_assoc($r);
$total = $row['cnt'];//总的记录条数
$total_pages = ceil(intval($total)/$pagesize);//总页数
$pn = isset($_GET['page']) ? intval($_GET['page']) : 1;
$pn $pn >= $total_pages && $pn = $total_pages;
$offset = ($pn - 1)*$pagesize;
$sql = "SELECT com,com_name FROM com_info LIMIT {$offset},{$pagesize}";
$r = mysql_query($sql) or die('error code:' . mysql_errno() . ',error:' . mysql_error());
?>
编号 | 公司名 |
---|---|