首頁 >後端開發 >php教程 >参数确实是true,但是仍是有警告mysql_fetch_row() expects parameter 1 to be resource

参数确实是true,但是仍是有警告mysql_fetch_row() expects parameter 1 to be resource

WBOY
WBOY原創
2016-06-13 12:17:552198瀏覽

参数确实是true,但是还是有警告mysql_fetch_row() expects parameter 1 to be resource?

<br />function checkCancelUserStop($phoneNum)<br />{<br />	$con = mysql_connect("localhost", "root", "");<br />	if(!$con)<br />	{<br />		echo "<script language=\"JavaScript\"><br />			 alert('数据库连接失败!');  <br />			 </script>";<br />		echo "<script language='javascript' type='text/javascript'>";<br />		echo "window.location.href='$url'";<br />		echo "</script>";<br />		return;<br />	}	<br />	$result = mysql_select_db ("teleservice",$con);<br />	if(!$result)<br />	{<br />		echo "<script language=\"JavaScript\"><br />			 alert('选择数据库失败!');  <br />			 </script>";<br />		echo "<script language='javascript' type='text/javascript'>";<br />		echo "window.location.href='$url'";<br />		echo "</script>";<br />		return;<br />	}<br />	$result = mysql_query("SET NAMES 'GBK'");<br />	if(!$result)<br />	{<br />		echo "<script language=\"JavaScript\"><br />			 alert('设置字符集失败!');  <br />			 </script>";<br />		echo "<script language='javascript' type='text/javascript'>";<br />		echo "window.location.href='$url'";<br />		echo "</script>";<br />		return;<br />	}<br />	$query = "select state<br />			  from phoneDetail<br />			  where phoneDetail.phoneNum = $phoneNum";<br />	if($result) <br />	{<br />		echo "<script language=\"JavaScript\"><br />			 alert('查询号码原状态成功!');  <br />			 </script>";<br />		echo "<script language='javascript' type='text/javascript'>";<br />		echo "window.location.href='$url'";<br />		echo "</script>";		<br />	} else {<br />		echo "<script language=\"JavaScript\"><br />			 alert('查询号码原状态失败!');  <br />			 </script>";<br />		echo "<script language='javascript' type='text/javascript'>";<br />		echo "window.location.href='$url'";<br />		echo "</script>";<br />		return;<br />	}<br />	$oldState = "正常开通";<br />	while($row = mysql_fetch_row($result))<br />	{<br />		echo "in while loop...";<br />		$oldState = $row[0];<br />		echo $oldState;<br />	}<br />	if($oldState == "主动停机") {<br />		echo "yes";<br />		return true;<br />	} else {<br />		echo "no";<br />		return false;<br />	}<br />	mysql_close($con);<br />}


问题:通过调试,已经可以成功查询到号码的原状态。此时$result = 1;但是后面fetch_row的时候,不能进入到while循环中,出现了警告:Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in H:\wamp\www\frr_cancelUserStop.php on line 58
请问:$result = 1确实是1(true)的啊,那为什么进不了循环?
怎么才能取得结果呢?
谢谢各位!
------解决思路----------------------
SQL 指令为执行

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn