Home >Backend Development >PHP Tutorial >php多条件附加查询

php多条件附加查询

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 11:47:31928browse

php多条件叠加查询

<?<br />header("Content-Type:text/html;charset=utf-8");<br />include("../manage/include/function.php");<br />	$brand=substr($_POST["brand"],0,strlen($_POST["brand"])-1); <br />	$color=substr($_POST["color"],0,strlen($_POST["color"])-1); <br />	$caizhi=$_POST["caizhi"];<br />	$style=$_POST["style"];<br />	$kucun=$_POST["kucun"];<br />	echo($brand."</br>");<br />	echo($color."</br>");<br />	echo($caizhi."</br>");<br />	echo($style."</br>");<br />	echo($kucun);<br />	<br />	$q="select * from pros_pro where (1=1)";<br />	if($brand!=null){<br />		$q=$q+"and psp_brand in(".$brand.")";<br />	}<br />	if($color!=null){<br />		$q=$q+"and psp_color in(".$color.")";<br />	}<br />	if($caizhi!=null){<br />		$q=$q+"and psp_caizhi='".$caizhi."'";<br />	}<br />	if($style!=null){<br />		$q=$q+"and psp_style='".$style."'";<br />	}<br />	if($kucun!=null){<br />		$q=$q+"order by psp_stock desc";<br />	}else<br />	{<br />		$q=$q+"order by psp_id desc";<br />	}<br />	<br /><br />	$rows=query($q);<br />	if($row=mysql_fetch_array($rows))<br />	{<br />		do{<br />?><br />			<td align='right'><div align='center'><?php echo $row['psp_name'];?></div></td><br />	<?    }while($row=mysql_fetch_array($rows));<br />	}<br />	else<br />	{?><br />		<td align='right'><div align='center'>没有符合条件的信息,请重新定义搜索条件!</div></td><br />	<?<br />	}<br />	?>	


这个代码有神马问题?为什么会报错:Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /data/home/hmu069081/htdocs/products/get_post.php on line 37
且没有符合条件的信息,可是我选的条件明明是有记录的
------解决方案--------------------
把所有形如
$q=$q+"and psp_brand in(".$brand.")";
这样的语句,改成形如这样的
$q = $q ." and psp_brand in(".$brand.")";

$q .= " and psp_brand in(".$brand.")";

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn