多个查询条件的sql话语的拼写技巧,求指点

WBOY
Release: 2016-06-13 12:38:39
Original
822 people have browsed it

多个查询条件的sql语句的拼写技巧,求指点。
多个查询条件的sql语句的拼写技巧,求指点。

<br />
$sql="select * from tb1";<br />
if($id=$_GET['id'])<br />
{<br />
	$where.=" where id like "%$id%"";<br />
}<br />
if($name=$_GET['name'])<br />
{<br />
	$where.=" where name like "%$name%"";<br />
}<br />
<br />
//当id有值的时候<br />
sql=select * from tb1 where id like "%$id%"<br />
//当name有值的时候<br />
sql=select * from tb1 where name like "%$name%"<br />
<br />
//当同时又值的时候,sql就出错了<br />
sql=select * from tb1 where name like "%$name%" where where id like "%$id%" <br />
<br />
//当然你可以说用<br />
if($id=$_GET['id']&&$name=$_GET['name'])<br />
{<br />
	where.= "and";<br />
}<br />
Copy after login

我举的例子只有两个条件,实际项目中我这里有十几个条件,这种方式肯定不行。
求更好的拼接方式

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!