急!请高人指点一下,这段代码错在哪里,应该怎样改正!多谢!
时间:2011-05-19
来源:互联网
class instance{
private static $mysqli;
public $username="root";/*数据库用户名*/
public $passwd="root";/*数据库密码*/
static function create_mysqli(){
if (!self::$mysqli){
self::$mysqli= new mysqli($this->username,$this->passwd,"caocao");
}/*if循环结束*/
return self::$mysqli;
}/*create_mysqli()函数结束*/
}/*类结束*/
class display_content{
private $sql;/*传入的SQL语句用于获得总共的记录*/
private $page_size;/*每页显示多少条*/
private $comment_page_size;/*每条显示多少评论*/
private $show_comment;/*是否显示评论true或者false*/
private $pages;/*总页数*/
private $current_page;/*当前页数*/
private $conn;/*数据库连接句柄*/
function __construct($sql,$page_size,$comment_page_size,$show_comment){/*赋值*/
$this->sql=$sql;
$this->page_size=$page_size;
$this->comment_page_size=$comment_page_size;
$this->show_comment=$show_comment;
$this->conn=instance::create_mysqli();
}
function get_pages(){/*获得总页数*/
$result=$this->conn->query($this->sql);
$num=$result->num_rows;
if ($num%$this->page_size!=0){
$pages=($num/$this->page_size)+1;
}else {
$pages=$num/$this->page_size;
}
$this->pages=$pages;
return $this->pages;
}/*函数结束*/
function get_array(){/*获得查询得到的数组*/
$this->conn->query("set names 'utf8'");
if ($this->current_page<=$this->pages){
$current_page=$this->current_page;
}else {
$current_page=$this->pages;
}/*判断所得当前页是否超过总页数*/
$query=$this->sql."limit 0 ,".$current_page."order by ID DESC";
$result=$this->conn->query($query);
while ($row=$result->fetch_assoc()){
if ($this->show_comment==true){
$this->conn->query("set names 'utf8'");
$query2="select * from caocao_comment where main_channel_ID=1 and second_channel_ID=".$row['ID']."limit 0 ,".$this->comment_page_size."order by ID DESC";
$result2=$this->conn->query($query2);
while ($row2=$result2->fetch_assoc()){
$comment[]=array('comment_id'=>$row2['ID'],'comment_date'=>$row2['date'],'comment_time'=>$row2['time'],'comment_content'=>$row2['content']);
}/*循环显示评论*/
unset($comment);
$row['comment']=$comment;
$array=array('arry'=>$row);
return $array;
}/*如果需要显示评论*/else {
$array=array('array'=>$row);
}/*如果不需要显示评论*/
}/*外部项目循环*/
}/*函数get_array()结束*/
function __destruct(){/*注销数据库连接*/
$this->conn->close();
}
}/*类结束*/
在此,先谢谢大家了!
private static $mysqli;
public $username="root";/*数据库用户名*/
public $passwd="root";/*数据库密码*/
static function create_mysqli(){
if (!self::$mysqli){
self::$mysqli= new mysqli($this->username,$this->passwd,"caocao");
}/*if循环结束*/
return self::$mysqli;
}/*create_mysqli()函数结束*/
}/*类结束*/
class display_content{
private $sql;/*传入的SQL语句用于获得总共的记录*/
private $page_size;/*每页显示多少条*/
private $comment_page_size;/*每条显示多少评论*/
private $show_comment;/*是否显示评论true或者false*/
private $pages;/*总页数*/
private $current_page;/*当前页数*/
private $conn;/*数据库连接句柄*/
function __construct($sql,$page_size,$comment_page_size,$show_comment){/*赋值*/
$this->sql=$sql;
$this->page_size=$page_size;
$this->comment_page_size=$comment_page_size;
$this->show_comment=$show_comment;
$this->conn=instance::create_mysqli();
}
function get_pages(){/*获得总页数*/
$result=$this->conn->query($this->sql);
$num=$result->num_rows;
if ($num%$this->page_size!=0){
$pages=($num/$this->page_size)+1;
}else {
$pages=$num/$this->page_size;
}
$this->pages=$pages;
return $this->pages;
}/*函数结束*/
function get_array(){/*获得查询得到的数组*/
$this->conn->query("set names 'utf8'");
if ($this->current_page<=$this->pages){
$current_page=$this->current_page;
}else {
$current_page=$this->pages;
}/*判断所得当前页是否超过总页数*/
$query=$this->sql."limit 0 ,".$current_page."order by ID DESC";
$result=$this->conn->query($query);
while ($row=$result->fetch_assoc()){
if ($this->show_comment==true){
$this->conn->query("set names 'utf8'");
$query2="select * from caocao_comment where main_channel_ID=1 and second_channel_ID=".$row['ID']."limit 0 ,".$this->comment_page_size."order by ID DESC";
$result2=$this->conn->query($query2);
while ($row2=$result2->fetch_assoc()){
$comment[]=array('comment_id'=>$row2['ID'],'comment_date'=>$row2['date'],'comment_time'=>$row2['time'],'comment_content'=>$row2['content']);
}/*循环显示评论*/
unset($comment);
$row['comment']=$comment;
$array=array('arry'=>$row);
return $array;
}/*如果需要显示评论*/else {
$array=array('array'=>$row);
}/*如果不需要显示评论*/
}/*外部项目循环*/
}/*函数get_array()结束*/
function __destruct(){/*注销数据库连接*/
$this->conn->close();
}
}/*类结束*/
在此,先谢谢大家了!
作者: PainsOnline 发布时间: 2011-05-19
错在哪里PHP会告诉你,把错误信息发上来,拜托。
作者: T5500 发布时间: 2011-05-19
看看错误信息先~
作者: zhukai1 发布时间: 2011-05-19
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28