PHP 完美结合 MYSQL 数据库记录分页显示
在
编程时,不可避免的要考虑到数据库记录结果的显示问题,为了呈现美
现把与
php 完美结合的
mysql 数据库为 xinxiku,数据表为 joke。其定义 sql 语句如下:
create table joke (
id int(5) not null auto_increment,
biaoti varchar(40) not null,
neirong text not null,
imary key (id)
);
字段说明:
id :记录号,自动递增且为主键
biaoti :标题
neirong :内容
<html>
<head>
<title>分页显示的实现方法</title>
<meta http-equiv=”content-type” content=”text/html; charset=gb2312″>
<scr
script”>
/* 定义一弹出窗口,来显示具体内容*/
function popwin(url)
{
window.open(url,”",”left=340, top=190, height=280, width=400, resizable=yes, scrollbars=yes,
status=no, toolbar=no, menubar=no, location=no”);
}
</script>
</head>
<body leftmargin=0 topmargin=0 rightmargin=0 >
<?php
//连接数据库
$db=mysql_connect(”localhost”,”root”,”");
mysql_select_db(”xinxiku”,$db);
//设定每一页显示的记录数
$pagesize=15;
//取得记录总数,计算总页数用
$res=mysql_query(”select count(*) from joke ” ,$db);
$myrow = mysql_fetch_array($res);
$numrows=$myrow[0];
//计算总页数
$pages=intval($numrows/$pagesize);
if ($numrows%$pagesize)
$pages++;