猿问

死循环,求大神帮忙!!!?实在看不出来

<?php
header('content-type:text/html;charset=utf8');
class mysql{
var $hname;
var $uname;
var $uwpd;
var $port;
var $charset;
var $dbname;
public function __construct($hostname,$uname,$uwpd,$port,$charset,$dbname)//构造函数
{
$this->hname=$hostname;
$this->uname=$uname;
$this->uwpd=$uwpd;
$this->port=$port;
$this->charset=$charset;
$this->dbname=$dbname;
}
public function connect()
{
mysql_connect($this->hname,$this->uname,$this->uwpd);
mysql_set_charset($this->charset);
mysql_select_db($this->dbname);
}

public function query($sql)
{
return mysql_query($sql);
}

public function num_rows($sql)
{
$query=mysql_query($sql);
return mysql_num_rows($query);
}

public function Allfetch($sql)
{
$arr=array();
$query=mysql_query($sql);
while($rs=mysql_fetch_assoc($query))
{
$arr[]=$rs;
}
return $arr;
}

public function fetch($sql)
{
$rs=array();
$query=mysql_query($sql);
return $rs=mysql_fetch_assoc($query);
}
}
$db=new mysql('localhost','root','root','3306','utf8','zhuce');
$db->connect();
$sql="select * from admin where 1 ";
?>
<table border="1">
<tr>
<td>用户名:</td>
<td>密码:</td>
</tr>
<?php
while($db->Allfetch($sql)){
?>
<tr>
<td><?php echo $arr['user']; ?></td>
<td><?php echo $arr['pwd']; ?></td>
</tr>
<?php }?>
</table>

赵昊昊
浏览 1330回答 1
1回答

phper_linuxer

<?phpwhile($db->Allfetch($sql)){?>这里你得把结果集取出来再循环啊,你这是循环取结果集,不是死循环是啥....................<?php$all_result = $db->Allfetch($sql);foreach($all_result as $result) {?>
随时随地看视频慕课网APP
我要回答