显示页面(index.php):<?php
include "conn.php" ;
include "Page.php" ;
$unhtml=new Page("select * from forum" , 3 , $_GET["pages"] , "公告" , "条") ;
echo "<p align=center><font color=green size=+3>论坛专题信息展示</font></p> ";
echo "<a href='addforum.html'><b>增加讨论话题</b></a></br>" ;
第13行:$arr=mysql_fetch_object($unhtml->query()) ;
do{
?>
<table cellpadding=0 cellspacing=0 border=0 align=center>
<tr>
<td><a href="talkshow.php?talkid=<?php echo $arr->talkid ; ?>" >讨论主题</a> <?php echo $arr->talktitle ; ?> </td>
<td> <a href="search.php?talkid=<?php echo $arr->talkid ; ?>" >搜索</a></td>
<td> <a href="forupdate.php?talkid=<?php echo $arr->talkid ; ?>" >编辑</a></td>
</tr>
<tr>
<td>讨论内容 </td>
<td><?php echo $arr->talkcontent ; ?> </td>
<td> <a href="fordelete.php?talkid=<?php echo $arr->talkid ; ?>" >删除</a></td>
</tr>
</table>
<hr width="50%" color="red">
<?php
第30行: }while($arr=mysql_fetch_object($unhtml->query())) ;
?>
<table cellpadding=0 cellspacing=0 border=0 align=right>
<tr>
<td colspan=3 align=right><?php echo $unhtml->show() ; ?></td>
</tr>
</table>
<?php
mysql_close($conn) ;
?>分页Page.php代码:<?php
class Page{
var $sql ;
var $pages ;
var $pageSize ;
var $totalPage ;
var $amount ;
var $content ;
var $utits ;
function __construct($sql , $pageSize , $pages , $content , $utits){
$this->sql=$sql ;
$this->pages=$pages ;
$this->content=$content ;
$this->utits=$utits ;
$this->pageSize=$pageSize ;
if(!isset($this->pages) || $this->pages=="" || $this->pages==0){
$this->pages = 1 ;
}
else{
$this->pages=$this->pages ;
}
第28行: $this->amount=mysql_result(mysql_query("select count(*) as amount from forum order by id desc") , 0 , "amount") ;
if($this->amount==0){
return false ;
}
else{
if(($this->amount % $this->pageSize)==0){
$this->totalPage=intval($this->amount / $this->pageSize) ;
}
else if($this->amount <= $this->pageSize){
$this->totalPage=1 ;
}
else{
$this->totalPage=ceil($this->amount / $this->pageSize) ;
}
}
}
function query(){
$mysql=mysql_query($this->sql . "limit" . ($this->pages - 1) * $this->pageSize . ", $this->pageSize") ;
return $mysql ;
} function show(){
$string .="共有" . $this->content . " " . $this->amount . " " . $this->utits . " 每页显示 " . $this->pageSize . " " . $this->utits . " 第 " . $this->pages . " 页/共 " . $this->totalPage . " 页 " ; $string .= "<a href=" . $_SERVER['PHP_SELF'] . "?page=1> 首页 </a>" ;
$string .=" " ; if(($this->pages - 1) <=0){
$string .= "<a href=" . $_SERVER['PHP_SELF'] . "?page=1> 上一页 </a>" ;
}
else{
$string .= "<a href=" . $_SERVER['PHP_SELF'] . "?page=" .($this->pages - 1). "> 上一页 </a>" ;
} if(($this->pages + 1) >=$this->totalPage){
$string .= "<a href=" . $_SERVER['PHP_SELF'] . "?page=".$this->totalPage."> 下一页 </a>" ;
}
else{
$string .= "<a href=" . $_SERVER['PHP_SELF'] . "?page=" .($this->pages + 1). "> 下一页 </a>" ;
} $string .= "<a href=" . $_SERVER['PHP_SELF'] . "?page=" .$this->totalPage. "> 尾页 </a>" ;
return $string ;
}
}
?>出现的问题:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in D:\www\zwt\forum\Page.php on line 28论坛专题信息展示增加讨论话题Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in D:\www\zwt\forum\index.php on line 13
讨论主题 搜索 编辑
讨论内容 删除 --------------------------------------------------------------------------------Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in D:\www\zwt\forum\index.php on line 30
共有公告 条 每页显示 3 条 第 1 页/共 页 首页 上一页 下一页 尾页
include "conn.php" ;
include "Page.php" ;
$unhtml=new Page("select * from forum" , 3 , $_GET["pages"] , "公告" , "条") ;
echo "<p align=center><font color=green size=+3>论坛专题信息展示</font></p> ";
echo "<a href='addforum.html'><b>增加讨论话题</b></a></br>" ;
第13行:$arr=mysql_fetch_object($unhtml->query()) ;
do{
?>
<table cellpadding=0 cellspacing=0 border=0 align=center>
<tr>
<td><a href="talkshow.php?talkid=<?php echo $arr->talkid ; ?>" >讨论主题</a> <?php echo $arr->talktitle ; ?> </td>
<td> <a href="search.php?talkid=<?php echo $arr->talkid ; ?>" >搜索</a></td>
<td> <a href="forupdate.php?talkid=<?php echo $arr->talkid ; ?>" >编辑</a></td>
</tr>
<tr>
<td>讨论内容 </td>
<td><?php echo $arr->talkcontent ; ?> </td>
<td> <a href="fordelete.php?talkid=<?php echo $arr->talkid ; ?>" >删除</a></td>
</tr>
</table>
<hr width="50%" color="red">
<?php
第30行: }while($arr=mysql_fetch_object($unhtml->query())) ;
?>
<table cellpadding=0 cellspacing=0 border=0 align=right>
<tr>
<td colspan=3 align=right><?php echo $unhtml->show() ; ?></td>
</tr>
</table>
<?php
mysql_close($conn) ;
?>分页Page.php代码:<?php
class Page{
var $sql ;
var $pages ;
var $pageSize ;
var $totalPage ;
var $amount ;
var $content ;
var $utits ;
function __construct($sql , $pageSize , $pages , $content , $utits){
$this->sql=$sql ;
$this->pages=$pages ;
$this->content=$content ;
$this->utits=$utits ;
$this->pageSize=$pageSize ;
if(!isset($this->pages) || $this->pages=="" || $this->pages==0){
$this->pages = 1 ;
}
else{
$this->pages=$this->pages ;
}
第28行: $this->amount=mysql_result(mysql_query("select count(*) as amount from forum order by id desc") , 0 , "amount") ;
if($this->amount==0){
return false ;
}
else{
if(($this->amount % $this->pageSize)==0){
$this->totalPage=intval($this->amount / $this->pageSize) ;
}
else if($this->amount <= $this->pageSize){
$this->totalPage=1 ;
}
else{
$this->totalPage=ceil($this->amount / $this->pageSize) ;
}
}
}
function query(){
$mysql=mysql_query($this->sql . "limit" . ($this->pages - 1) * $this->pageSize . ", $this->pageSize") ;
return $mysql ;
} function show(){
$string .="共有" . $this->content . " " . $this->amount . " " . $this->utits . " 每页显示 " . $this->pageSize . " " . $this->utits . " 第 " . $this->pages . " 页/共 " . $this->totalPage . " 页 " ; $string .= "<a href=" . $_SERVER['PHP_SELF'] . "?page=1> 首页 </a>" ;
$string .=" " ; if(($this->pages - 1) <=0){
$string .= "<a href=" . $_SERVER['PHP_SELF'] . "?page=1> 上一页 </a>" ;
}
else{
$string .= "<a href=" . $_SERVER['PHP_SELF'] . "?page=" .($this->pages - 1). "> 上一页 </a>" ;
} if(($this->pages + 1) >=$this->totalPage){
$string .= "<a href=" . $_SERVER['PHP_SELF'] . "?page=".$this->totalPage."> 下一页 </a>" ;
}
else{
$string .= "<a href=" . $_SERVER['PHP_SELF'] . "?page=" .($this->pages + 1). "> 下一页 </a>" ;
} $string .= "<a href=" . $_SERVER['PHP_SELF'] . "?page=" .$this->totalPage. "> 尾页 </a>" ;
return $string ;
}
}
?>出现的问题:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in D:\www\zwt\forum\Page.php on line 28论坛专题信息展示增加讨论话题Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in D:\www\zwt\forum\index.php on line 13
讨论主题 搜索 编辑
讨论内容 删除 --------------------------------------------------------------------------------Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in D:\www\zwt\forum\index.php on line 30
共有公告 条 每页显示 3 条 第 1 页/共 页 首页 上一页 下一页 尾页
echo $unhtml; //贴出结果function query(){
$mysql=mysql_query($this->sql . " limit " . ($this->pages - 1) * $this->pageSize . ", $this->pageSize") ;
return $mysql ;
}
mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysql_error());
mysql_select_db("mydb"); $result = mysql_query("SELECT id, name FROM mytable"); while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
printf ("ID: %s Name: %s", $row[0], $row[1]);
} mysql_free_result($result);
mysql_query("select count(*) as amount from forum order by id desc") or die(mysql_error());
贴出结果