Home > Backend Development > PHP Tutorial > php,混编,数据分页

php,混编,数据分页

WBOY
Release: 2016-06-23 13:13:26
Original
851 people have browsed it

连接数据库

$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());

?>

混编数据分页





测试分页


include 'conn.php';

$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());

?>



while ($row = mysql_fetch_assoc($r)) {
?>

}
?>
编号 公司名


首页
for ($i = 1; $i ?>

}

?>
末页



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template