select abcd from `goods` as g where is_delete = 0 and is_alone_sale = 1 and ( 1 and cat_id in ( '8 ', ' ') and (0 or goods_name like '%高级商务% ' or goods_sn like '%高级商务% ' or keywords like '%高级商务% ' ) ) or goods_id in ( ' ') order by goods_id desc
上面的这条查询语句运行无错,我现在去掉and (1中的1,这样运行后打印出如下sql语句:
select abcd from `goods` as g where is_delete = 0 and is_alone_sale = 1 and ( and cat_id in ( '8 ', ' ') and (0 or goods_name like '%高级商务% ' or goods_sn like '%高级商务% ' or keywords like '%高级商务% ' ) ) or goods_id in ( ' ') order by goods_id desc
请看and ( 这儿,这儿比原来的少了1,但运行出错了,提示如下:
fatal error: call to a member function on a non-object in search.php on line 278
想不通去掉了这个1运行就无效了,这里的1是不是is_delete = 0 and is_alone_sale = 1这两个表达式的结果值?如果我的理解不对,请大家纠正一下。
还有,and (0这儿,这里的0也是哪个表达式的结果值吗?如果不是,那代表什么意思?
以上是逻辑运算方面的,我对照手册看了半天还是无法理解,恳请得到大家的帮助,谢谢。
------解决方案--------------------
当然了,这个有括号啊!
括号里面的是一个整体
and cat_id in ( '8 ', ' ') and (0 or goods_name like '%高级商务% ' or goods_sn like '%高级商务% ' or keywords like '%高级商务% ' )
这样的语句对吗?
或许 sql 解析器认为 开头的and 是个 函数 故而出现了那样的错误,1 是必不可少的!
------解决方案--------------------
...
你不会不知道逻辑表达是 a and b 吧。。。。。
你把 a and b 写成 and b 当然会错。。。
你再把1后面的and去掉就好了。。。
晕。。。
1 and 。。。。 这个写法仅仅是为了sql语句组合的方便
与的开始给个1 (true) ,后面的就可以 and a1 and a2 的不断加条件了。。。表单生成的。
楼主应该找任意一本编程语言书再温习一下基础知识。。。
