求助mysql+php分页程序!我写的代码出错!谢谢!! 15
<?$query="select*from25bbs";$result=mysql_query($query);$num=mysql_num_rows($result);...
<?
$query="select * from 25bbs ";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if(isset($_GET["pape"]))
{
$page=intval($_GET["page"]);
}
else {
$pape=1;
}
$myjv=10;
if($num<$myjv)
{
$zongye=1;
}
$zongye=$num/$myjv;
$yu=$num%$myjv;
if ($yu<>0){
$zongye=$zongye+1;
}
else {
$zongye=$num/$myjv;
}
if ($page==1)
$page_string='diyiye|<a href=25yemian.php?page='.($page+1).'>xiayiye</a>|';
elseif(($page==$num)||($num==0))
$page_string='<a href=25yemian.php?page='.($page-1).'>shangyiye</a>|<a href=a href=25yemian.php?page='.$num.'>muye</a>';
elseif(($page>1)&&($page<$num))
$page_string='<a href=ceshi.php?page='.($page-1).'>shangyiye</a>|<a href=25yemian.php?page='.($page+1).'>xiayiye</a>|';
$a=($page-1)*$myjv;
$b=$myjv;
$query="select * from 25bbs order by 25bbs_id limit $a,$b";
mysql_query($query);
echo 'yigongyou'.$num.'ye<p>';
echo 'dangqiandi'.$page.'ye<p>';
echo $page_string;
?> 展开
$query="select * from 25bbs ";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if(isset($_GET["pape"]))
{
$page=intval($_GET["page"]);
}
else {
$pape=1;
}
$myjv=10;
if($num<$myjv)
{
$zongye=1;
}
$zongye=$num/$myjv;
$yu=$num%$myjv;
if ($yu<>0){
$zongye=$zongye+1;
}
else {
$zongye=$num/$myjv;
}
if ($page==1)
$page_string='diyiye|<a href=25yemian.php?page='.($page+1).'>xiayiye</a>|';
elseif(($page==$num)||($num==0))
$page_string='<a href=25yemian.php?page='.($page-1).'>shangyiye</a>|<a href=a href=25yemian.php?page='.$num.'>muye</a>';
elseif(($page>1)&&($page<$num))
$page_string='<a href=ceshi.php?page='.($page-1).'>shangyiye</a>|<a href=25yemian.php?page='.($page+1).'>xiayiye</a>|';
$a=($page-1)*$myjv;
$b=$myjv;
$query="select * from 25bbs order by 25bbs_id limit $a,$b";
mysql_query($query);
echo 'yigongyou'.$num.'ye<p>';
echo 'dangqiandi'.$page.'ye<p>';
echo $page_string;
?> 展开
2个回答
展开全部
<?php
class page{
/*
类功能:分页
创建时间:2005-03-12
作者:多菜鸟
EMAIL:kingerq AT msn.com
来源:http://blog.csdn.net/kingerq
实例:
//省略一些连接信息及mysql类库等包含文件
$sql = "select count(*) from t_publiccode";
$db->query($sql);
$db->next_record();
$recordcount = $db->f(0);//记录总数
$p = new page($recordcount, 20, 15);//(总记录数,每页记录数,每面页码个数)
$p->ar = array("«首页", "‹前页", "后页›", "末页»");//可以设置成图片HTML代码
$trunpage = $p->show_page();//得到分页信息
$sql = "select * from t_publiccode".$p->limit();
//echo $trunpage."<br>".$sql;
$db->query($sql);
//...
类似效果:
共[52600]条记录/共[2630]页 <<首页 <前页 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 后页> 末页>>
*/
var $pagecount; //总页数
var $limit = ""; //分页时用到的limit参数
var $pagearg = "page"; //分页参数名称
var $pagesize = 20; //每页显示记录数
var $recordcount; //总记录数
var $pagenum; //当前页码
var $argstr = ""; //GET参数字符串
var $perpage = 5; //每次显示页码个数
var $ar = array("[«]", "[‹]", "[›]", "[»]");
/*
* 功能:构造函数
* 参数 $recordcount 为记录总数
* 参数 $pagesize 为每页显示记录数,默认为20
* 参数 $perpage 为每次显示页码个数,默认为5
*/
function page($recordcount, $pagesize = 20, $perpage = 5){
$this->pagesize = $pagesize;
$this->recordcount = $recordcount;
$this->perpage = $perpage;
$this->pagecount = ceil($recordcount/$pagesize);//总页数
$this->pagenum = $this->currentpage();//当前页码
$this->argstr = $this->newarg();//GET参数字符串
$this->limit = " LIMIT ".($this->pagenum-1)*$pagesize.",".$pagesize;//分页时用到的limit参数
}
/*
* 功能:取得当前页码函数
*/
function currentpage(){
if(isset($_GET[$this->pagearg])){
if($_GET[$this->pagearg] <= 0) {
$page = 1;
}else if($_GET[$this->pagearg] > $this->pagecount){
$page = $this->pagecount;
}else{
$page = $_GET[$this->pagearg];
}
}else {
$page = 1;
}
return $page;
}
/*
* 功能:重新整理GET参数
*/
function newarg(){
$str = "";
$urlar = $_GET;
unset($urlar[$this->pagearg]);
if($urlar){
foreach($urlar as $key=>$val){
if($str == "") {
$str = "?$key=$val";
}else {
$str .= "&$key=$val";
}
}
$str .= "&$this->pagearg=";
}else{
$str = "?$this->pagearg=";
}
return $str;
}
/*
* 功能:返回MYSQL语句的limit部分代码
*/
function limit(){
return $this->limit;
}
/*
* 功能:分页字符输出函数
*/
function show_page(){
$trunpage = " 共[".$this->recordcount."]条记录/共[".$this->pagecount."]页 ";
$page = $this->pagenum;
//向前翻
if($page == 1){
$trunpage .= $this->ar[0]." ".$this->ar[1]." ";
}else {
$trunpage .= '<a href="'.$this->argstr.'1" class=word_link_bac>'.$this->ar[0].'</a> <a href="'.$this->argstr.($page-1).'" class=word_link_bac>'.$this->ar[1].'</a> ';
}
//中间数字翻页
$numpage = 1;
while($page - $this->perpage * $numpage > 0) $numpage++;
$startpage = ($numpage - 1) * $this->perpage;
$endpage = $this->pagecount < $numpage * $this->perpage ? $this->pagecount : $numpage * $this->perpage;
for($i = $startpage + 1; $i <= $endpage; $i++){
$trunpage .= $i != $page ? "<a href=\"".$this->argstr.$i."\" class=word_link_bac>$i</a> " : "<strong>".$i."</strong> ";
}
//向后翻
if($page == $this->pagecount || $this->pagecount == 0){
$trunpage .= $this->ar[2]." ".$this->ar[3]." ";
}else {
$trunpage .= '<a href="'.$this->argstr.($page+1).'" class=word_link_bac>'.$this->ar[2].'</a> <a href="'.$this->argstr.$this->pagecount.'" class=word_link_bac>'.$this->ar[3].'</a> ';
}
//跳转
$select = "<select onchange='location.href=this.options[this.selectedIndex].value'>\n";
for($i = 1; $i <= $this->pagecount; $i++){
$select .= "<option value=\"".$this->argstr.$i."\">$i</option>\n";
}
$select .= "</select>";
return $trunpage.$select;
}
}
?>
转的,我不常用,肯定能用!
class page{
/*
类功能:分页
创建时间:2005-03-12
作者:多菜鸟
EMAIL:kingerq AT msn.com
来源:http://blog.csdn.net/kingerq
实例:
//省略一些连接信息及mysql类库等包含文件
$sql = "select count(*) from t_publiccode";
$db->query($sql);
$db->next_record();
$recordcount = $db->f(0);//记录总数
$p = new page($recordcount, 20, 15);//(总记录数,每页记录数,每面页码个数)
$p->ar = array("«首页", "‹前页", "后页›", "末页»");//可以设置成图片HTML代码
$trunpage = $p->show_page();//得到分页信息
$sql = "select * from t_publiccode".$p->limit();
//echo $trunpage."<br>".$sql;
$db->query($sql);
//...
类似效果:
共[52600]条记录/共[2630]页 <<首页 <前页 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 后页> 末页>>
*/
var $pagecount; //总页数
var $limit = ""; //分页时用到的limit参数
var $pagearg = "page"; //分页参数名称
var $pagesize = 20; //每页显示记录数
var $recordcount; //总记录数
var $pagenum; //当前页码
var $argstr = ""; //GET参数字符串
var $perpage = 5; //每次显示页码个数
var $ar = array("[«]", "[‹]", "[›]", "[»]");
/*
* 功能:构造函数
* 参数 $recordcount 为记录总数
* 参数 $pagesize 为每页显示记录数,默认为20
* 参数 $perpage 为每次显示页码个数,默认为5
*/
function page($recordcount, $pagesize = 20, $perpage = 5){
$this->pagesize = $pagesize;
$this->recordcount = $recordcount;
$this->perpage = $perpage;
$this->pagecount = ceil($recordcount/$pagesize);//总页数
$this->pagenum = $this->currentpage();//当前页码
$this->argstr = $this->newarg();//GET参数字符串
$this->limit = " LIMIT ".($this->pagenum-1)*$pagesize.",".$pagesize;//分页时用到的limit参数
}
/*
* 功能:取得当前页码函数
*/
function currentpage(){
if(isset($_GET[$this->pagearg])){
if($_GET[$this->pagearg] <= 0) {
$page = 1;
}else if($_GET[$this->pagearg] > $this->pagecount){
$page = $this->pagecount;
}else{
$page = $_GET[$this->pagearg];
}
}else {
$page = 1;
}
return $page;
}
/*
* 功能:重新整理GET参数
*/
function newarg(){
$str = "";
$urlar = $_GET;
unset($urlar[$this->pagearg]);
if($urlar){
foreach($urlar as $key=>$val){
if($str == "") {
$str = "?$key=$val";
}else {
$str .= "&$key=$val";
}
}
$str .= "&$this->pagearg=";
}else{
$str = "?$this->pagearg=";
}
return $str;
}
/*
* 功能:返回MYSQL语句的limit部分代码
*/
function limit(){
return $this->limit;
}
/*
* 功能:分页字符输出函数
*/
function show_page(){
$trunpage = " 共[".$this->recordcount."]条记录/共[".$this->pagecount."]页 ";
$page = $this->pagenum;
//向前翻
if($page == 1){
$trunpage .= $this->ar[0]." ".$this->ar[1]." ";
}else {
$trunpage .= '<a href="'.$this->argstr.'1" class=word_link_bac>'.$this->ar[0].'</a> <a href="'.$this->argstr.($page-1).'" class=word_link_bac>'.$this->ar[1].'</a> ';
}
//中间数字翻页
$numpage = 1;
while($page - $this->perpage * $numpage > 0) $numpage++;
$startpage = ($numpage - 1) * $this->perpage;
$endpage = $this->pagecount < $numpage * $this->perpage ? $this->pagecount : $numpage * $this->perpage;
for($i = $startpage + 1; $i <= $endpage; $i++){
$trunpage .= $i != $page ? "<a href=\"".$this->argstr.$i."\" class=word_link_bac>$i</a> " : "<strong>".$i."</strong> ";
}
//向后翻
if($page == $this->pagecount || $this->pagecount == 0){
$trunpage .= $this->ar[2]." ".$this->ar[3]." ";
}else {
$trunpage .= '<a href="'.$this->argstr.($page+1).'" class=word_link_bac>'.$this->ar[2].'</a> <a href="'.$this->argstr.$this->pagecount.'" class=word_link_bac>'.$this->ar[3].'</a> ';
}
//跳转
$select = "<select onchange='location.href=this.options[this.selectedIndex].value'>\n";
for($i = 1; $i <= $this->pagecount; $i++){
$select .= "<option value=\"".$this->argstr.$i."\">$i</option>\n";
}
$select .= "</select>";
return $trunpage.$select;
}
}
?>
转的,我不常用,肯定能用!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询