作者:终-极-幻-想 | 来源:互联网 | 2023-09-12 17:47
后端开发|php教程quot,comparator,row,columnname,andor后端开发-php教程有and有OR的根据几个字段生成SQL语句有如下图的数据表信息,有什
后端开发|php教程
quot,comparator,row,columnname,andor
后端开发-php教程
有and 有OR的根据几个字段生成SQL语句
有如下图的数据表信息,有什么好的方法把它们组合成一条SQL?如果全是and 的或者全是or的,这方法好办,可是两个同时都有的,怎么办呢?
锁机源码网址,vscode提交代码工具,ubuntu日志信息,查询tomcat链接数,flask反爬虫,php调用其他文件函数,seo优化制造行业推广报价,全网vip视频解析网站源码二次解析,w3school 模板lzw
全是AND 或OR的话
asp.net源码模板,vscode打开数据库,Ubuntu测试Iperf,tomcat 安全性,胳膊爬虫子,php if k 1,酉阳智能化seo推广,如何给wordpress添加网站图标,齐博v7整站模板lzw
PHP code
教育培训源码下载,vscode跑node,ubuntu22.04支持时间,tomcat 8.5启动,sqlite下载32位,jq 上传excel插件下载,国内用得最多的前端框架,爬虫爬公开数据违法,php变量$this,建水seo成本,网站flash客服,任意修改网页代码,招聘文章模板下载lzw
$sql = "select * from sk_cvfilter where cvid=58 and columnname!=''"; $query = mysql_query($sql); $sql = ''; while($row = mysql_fetch_assoc($query)){ if($row['comparator']=='eq'){$comparator="=";} else{$comparator=$row['comparator'];} $sql .=$row['columnname'].$comparator."'".$row['value']."' ".$row['andor'].' '; }
——解决方案——————–
SQL code
select * from sk_cvfilter where cvid=58 and columnname!='' and andor='and' or andor='or'
------解决方案--------------------
你的这个记录有问题,为什么呢?
例如出现一个 (a = 1 or (b=2 and b=3)),这个时候,你是怎么记录的?
我猜是这样的
columnname comparator value andor
a eq 1 or
b eq 2 and
c eq 3
这个时候问题出现了,假如你不知道上面的那个关系式(a = 1 or (b=2 and b=3)),
如果只从结构看的话,你是认为
(a = 1 or b =2 ) and b = 3
还是
a = 1 or (b=2 and b=3)
上述问题不考虑,所有or为一个条件和其他条件and的写法
PHP code
------解决方案--------------------
PHP code