mysql|分頁|資料|顯示 建表及產生測試資料(mysql.sql):
create table pagetest(
id int unsigned not null primary key auto_increment,
name text not null
);
insert into pagetest(name) values('您好,朋友,這是分頁測試資料!');
insert into pagetest(name) values('第2條');
insert into pagetest(name) values('第3條');
insert into pagetest(name) values('第4條');
insert into pagetest(name) values('第5條');
insert into pagetest(name) values('第6條');
insert into pagetest(name) values('第7條');
insert into pagetest(name) values('第8條');
insert into pagetest(name) values('第9條');
insert into pagetest(name) values('第10條');
insert into pagetest(name) values('第11條');
insert into pagetest(name) values('第12條');
insert into pagetest(name) values('第13條');
顯示程式(mysql.php3):
<?
$pagesize = 2;//每頁顯示2條記錄
$server = mysql_pconnect("localhost","test","test") or die("無法串連到localhost主機上的MySQL資料庫伺服器!");//以test帳號、test密碼串連localhost主機上的MySQL資料庫
$db = mysql_select_db("test") or die("無法串連到test資料庫!");
$sql = "select count(*) as total from pagetest";//產生查詢記錄數的SQL語句
$rst = mysql_query($sql) or die("無法執行SQL語句:$sql !");//查詢記錄數
$row = mysql_fetch_array($rst) or die("沒有更多的記錄!");//取出一條記錄
$rowcount = $row["total"];//取出記錄數
mysql_free_result($rst) or die("無法釋放result資源!");//釋放result資源