求一个SQL查询语句:select * from Table wher A B C D
select * from Table wher A and B and C and D
其中,A,B,C,D为条件。应该怎样构造啊?
是不是要先判断a,b,c,d中,只要有一个不为空,则“where”
那AND呢?》
------解决方案--------------------
判断非空,拼sql字符串.一般先加 where 1=1 ,不会出现where and A了
------解决方案--------------------
hookee() 正解
------解决方案--------------------
hookee() 正解
where 1=1 和 where 1 != 1 在sql中会经常用到
1=1 为后面加东西做好铺垫,1 != 1 得到表的结构
------解决方案--------------------
$aWhere[] = " 1=1 ";
if(!empty($A))
$aWhere[] = $A;
if(!emtpy($B))
$aWhere[] = $B;
if(!empty($C))
$aWhere[] = $C;
if(!empty($D))
$aWhere[] = $D;
$sWhere = join( ' and ', $aWhere);
$sSql = "select * from tbl where $sWhere order by id desc ";
------解决方案--------------------
$condition = " ";
$link_symbol = " ";
if($a)
{
$condition .= "$link_symbol $a ";
$link_symbol = "and ";
}
依次类推
0
0
相关文章
ini_set()在PHP中的作用是什么?
在PHP中的readlink()函数
我们如何编写PHP脚本来释放与MySQL结果关联的游标内存?
PHP intdiv() 函数
我们如何使用PHP脚本删除MySQL数据库?
本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门AI工具









