Php应用实例--分页的技巧
时间:2005-02-18 来源:54xw
一,三个函数,一个观念:函数都有输入输出。
1,获取资料表的函数GetRows():
[color="#cc6600"]
$rows是函数的输出,作为存取资料的依据。
2,连结数据库的函数ConnectDatabase():
[color="#cc6600"]
3,显示一页的函数ShowOnePage():
[color="#cc6600"]";
echo "No.";
while ( $field = mysql_fetch_field($rows) ) {
echo "" . $field->name . "";
}
echo "";
[color="#cc6600"] for ( $I=1; $I " . ($No + $I) . "";
for ( $K=0 ; $K " . $row[$K] . "";
}
echo "";
}
}
echo "";
}
?>
输出为一张表格。
二,分页的技巧
Version1,只显示1到10条记录:
[color="#cc6600"]";
echo "No.";
while ( $field = mysql_fetch_field($rows) ) {
echo "" . $field->name . "";
}
echo "";
[color="#cc6600"] for ( $I=1; $I " . ($No + $I) . "";
for ( $K=0 ; $K " . $row[$K] . "";
}
echo "";
}
}
echo "";
}
?>
[color="#cc6600"]
pagev1.php3, Version 1 - だ??мォ
相关说明:1,$No参数,由于显示某一页,利用此参数指定该页的第一笔资料;
2,设定目前资料录的位子:mysql_data_seek($rows,$No);
3,判断是否还有资料录:if ($row=mysql_fetch_row($rows)).
Version2,可以在IE位置栏输入页次:
[color="#cc6600"]";
echo "No.";
while ( $field = mysql_fetch_field($rows) ) {
echo "" . $field->name . "";
}
echo "";
[color="#cc6600"] for ( $I=1; $I " . ($No + $I) . "";
for ( $K=0 ; $K " . $row[$K] . "";
}
echo "";
}
}
echo "";
}
?>
[color="#cc6600"]
pagev2.php3, Version 2 - だ??мォ
$Pages ) $Page = $Pages;
[color="#cc6600"] ShowOnePage( $rows, ($Page-1)*10 );
?>
?Ω:/
[color="#cc6600"]Version3,页次的浏览:
[color="#cc6600"] echo "";
echo "No.";
while ( $field = mysql_fetch_field($rows) ) {
echo "" . $field->name . "";
}
echo "";
[color="#cc6600"] for ( $I=1; $I " . ($No + $I) . "";
for ( $K=0 ; $K " . $row[$K] . "";
}
echo "";
}
}
echo "";
}
?>
[color="#cc6600"]
pagev3.php3, Version 3 - ?Ω?聅凝
$Pages ) $Page = $Pages;
[color="#cc6600"] ShowOnePage( $rows, ($Page-1)*10 );
?>
1 ) { // ?狦ぃ琌??材??
echo "材???";
echo "????";
}
[color="#cc6600"]if ( $Page $Pages ) { // ?狦ぃ琌??程???
echo "????";
echo "程????";
}
?>
?Ω:/
Version 4,完成版:
[color="#cc6600"]";
echo "No.";
while ( $field = mysql_fetch_field($rows) ) {
echo "" . $field->name . "";
}
echo "";
[color="#cc6600"] for ( $I=1; $I " . ($No + $I) . "";
for ( $K=0 ; $K " . $row[$K] . "";
}
echo "";
}
}
echo "";
}
?>
[color="#cc6600"]
pagev4.php3, だ?聅凝(ЧΘ?)
$Pages ) $Page = $Pages;
[color="#cc6600"] ShowOnePage( $rows, ($Page-1)*10 );
?>
Method=GET>
1 ) { // ?狦ぃ琌??材??
echo "材???";
echo "????";
}
[color="#cc6600"]if ( $Page $Pages ) { // ?狦ぃ琌??程???
echo "????";
echo "程????";
}
?>
块??Ω:
?Ω:/
作者:(台湾)王国荣
相关阅读 更多 +