Maison >développement back-end >tutoriel php >PHP函数内while 循环无效,该如何解决
PHP函数内while 循环无效
$conn = mysql_connect("localhost","root","root");//连接数据库,请填写你自己的用户名密码
mysql_select_db("hxxx");//选择MYSQL数据库
mysql_query("set names utf-8");//设置为gb2312编码
function Cliebiao($mingcheng1,$mingcheng2){
$liebiao="";
$rows="";
$result = mysql_query("select mingcheng,daima from mingcheng where leixing='".$mingcheng1."'");
echo "$mingcheng1: ";
return $liebiao;
}
$mingchenga="类型名称";
$mingchengb="mingcheng";
Cliebiao($mingchenga,$mingchengb);
?>
符合条件的数据是存在的,而且不只一条,可程序执行后没有显示数据,只有“”类型名称: “”
请各位大师指点一下哪的问题
------解决思路----------------------
while($rows = mysql_fetch_row($result)){
echo "";
}
把里面的mysql_fetch_row变成mysql_fetch_array
------解决思路----------------------
奥才看到原来你还有一个Cliebiao函数呢。你那些链接数据库的代码函数里面引用不到的
------解决思路----------------------
<br /><br />global $conn;<br />$result = mysql_query("select mingcheng,daima from mingcheng where leixing='".$mingcheng1."'",$conn);<br /><br />
<br /><?php<br />$conn = mysql_connect("localhost","root","root");//连接数据库,请填写你自己的用户名密码<br />mysql_select_db("hxxx");//选择MYSQL数据库 <br />mysql_query("set names utf-8");//设置为utf-8编码<br /><br />function Cliebiao($mingcheng1, $mingcheng2, $conn){<br /> $liebiao = "";<br /> $rows = "";<br /> $result = mysql_query("select mingcheng,daima from mingcheng where leixing='".$mingcheng1."'", $conn); <br /> $liebiao .= "$mingcheng1: <select name=$mingcheng2>";<br /> while($rows = mysql_fetch_array($result)){<br /> $liebiao .= "<option value=".$rows[1].">".$rows[0]."</option>";<br /> }<br /> $liebao .= "</select>";<br /> return $liebiao;<br />}<br />$mingchenga="类型名称";<br />$mingchengb="mingcheng";<br />echo Cliebiao($mingchenga, $mingchengb, $conn);<br />?><br />