while嵌套while循环,为什么只循环了外边的while 着与你的 db 类的 query 写法有关没看到,不好说 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public function query($sql) { if ($sql == "") { $this->show_error("SQL语句错误:", "SQL查询语句为空"); } $this->sql = $sql; $result = mysql_query($this->sql, $this->conn); if (!$result) { //调试中使用,sql语句出错时会自动打印出来 if ($this->show_error) { $this->show_error("错误SQL语句:", $this->sql); } } else { $this->result = $result; } return $this->result; }这是query的写法; 难道与return有关系? 这个函数应该如何修正,不用return要写什么; 看起来你用的好像是mysqli类,但是这个类的query返回是mysqli_result类,mysqli_result的fetch_array()不是这么用的。如果是mysqli类,应该是这样吧$query=$db->query("select * from `p_newsclass` where `f_id`='0' "); //f_id=0 主分类;while($row=$query->fetch_array()){ echo $row[id].$row[name];$sonquery=$db->query("select * from `p_newsclass` where `f_id`='$row[id]'");while($son=$sonquery->fetch_array()){echo $son[id].$son[name]; $query=$db->query("select * from `p_newsclass` where `f_id`='0' "); //f_id=0 主分类;$result = array();while($row=$db->fetch_array($query)){ $result[] = $row;}print_r($result);把数组打印出来看看有什么。 问题就出在 $this->result = $result; 上内层的查询结果呢把外层的覆盖掉了 不同的子类是否可以继承同一个父类 测试http://127.0.0.1/phpinfo.php 弹出迅雷下载 PHP 请教DOS窗口下,光标如何移动上面几行?? 不是说安装zend optimizer 速度能提上去嘛? 自己做的无限级分类,请大家pp 用php可以连接pop3的端口吗? if(mysql_num_rows($result) != 1)报错? PHP的类中有没有析构函数? 为何php文件在页面不同地方显示效果不一样 login.html.php这种是什么文件? 初学者学习PHP需要安装哪些软件
if ($sql == "") {
$this->show_error("SQL语句错误:", "SQL查询语句为空");
}
$this->sql = $sql; $result = mysql_query($this->sql, $this->conn); if (!$result) {
//调试中使用,sql语句出错时会自动打印出来
if ($this->show_error) {
$this->show_error("错误SQL语句:", $this->sql);
}
} else {
$this->result = $result;
}
return $this->result;
}这是query的写法; 难道与return有关系? 这个函数应该如何修正,不用return要写什么;
如果是mysqli类,应该是这样吧$query=$db->query("select * from `p_newsclass` where `f_id`='0' "); //f_id=0 主分类;
while($row=$query->fetch_array()){
echo $row[id].$row[name];
$sonquery=$db->query("select * from `p_newsclass` where `f_id`='$row[id]'");
while($son=$sonquery->fetch_array()){
echo $son[id].$son[name];
$query=$db->query("select * from `p_newsclass` where `f_id`='0' "); //f_id=0 主分类;
$result = array();
while($row=$db->fetch_array($query)){
$result[] = $row;
}print_r($result);
把数组打印出来看看有什么。
内层的查询结果呢把外层的覆盖掉了