首页 >后端开发 >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:552200浏览

参数确实是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