警告:mysql_query()期望参数1为字符串,资源在第20行的C:\ wamp \ www \ life \ homeSearch.php中给出
代码正在运行,但显示上述错误。这是代码:
<?php
ob_start();
require("config.php");
ob_end_clean();
$req=$_REQUEST['propertyType'];
$req2=$_REQUEST['propertyStatus'];
mysql_connect("localhost",$username,$password);
mysql_select_db("$database") or die( "Unable to select database");
if ($req!="all" && $req2!="all") $query= "SELECT * FROM buildings WHERE propertyType='$req' AND propertyStatus='$req2'";
else if($req=="all" && $req2!="all" ) $query= "SELECT * FROM buildings WHERE propertyStatus='$req2'";
else if($req!="all" && $req2=="all" ) $query= "SELECT * FROM buildings WHERE propertyType='$req'";
else if($req=="all" || $req2=="all" ) $query= "SELECT * FROM buildings";
$result=mysql_query($query);
$num=mysql_num_rows($result);
mysql_query($result);
mysql_close();
$i=0;
for ($i; $i < $num; $i++){
$f12=mysql_result($result,$i,"availability");
$f13=mysql_result($result,$i,"propertyType");
$f14=mysql_result($result,$i,"propertyStatus");
echo $f12." ".$f13." <br /> ".$f14."<br />";
}
?>
答案 0 :(得分:0)
您需要从代码中删除以下行以使警告消失:
mysql_query($result);
您已将$result
分配给查询结果几行:
$result=mysql_query($query);
所以它现在告诉你mysql_query($result);
无效,因为它需要一个字符串,而你实际上是将查询结果传递给它。