Php 在带有LIKE-的Where子句中使用通配符不会返回任何结果
编辑某些已删除可接受答案的内容:( 问题的解决方案是使用如下函数:Php 在带有LIKE-的Where子句中使用通配符不会返回任何结果,php,sql,database,web,sql-like,Php,Sql,Database,Web,Sql Like,编辑某些已删除可接受答案的内容:( 问题的解决方案是使用如下函数: ifnull(trees.primarycolor, '') LIKE %, 开始问题: 你好,网络上的朋友,家人,同事和陌生人。我有一个困境,这肯定会让网站管理员们兴奋不已 我的质询如下: $result = mysql_query("SELECT trees.* $bottom_query FROM trees INNER JOIN price ON trees.ID=price.treeid where tr
ifnull(trees.primarycolor, '') LIKE %,
开始问题:
你好,网络上的朋友,家人,同事和陌生人。我有一个困境,这肯定会让网站管理员们兴奋不已
我的质询如下:
$result = mysql_query("SELECT trees.*
$bottom_query
FROM trees
INNER JOIN price
ON trees.ID=price.treeid
where trees.primarycolor like
'$primary_color'
and trees.secondarycolor like
'$secondary_color'
and trees.fallcolor like
'$fall_color'
and trees.droughtresistant like
'$drought_resistant'
and trees.height like
'$height'
and trees.spread like
'$spread'
and trees.trunkcolor like
'$trunk_color'
and trees.flowering like
'$flowering'
and trees.fruitproducing like
'$fruit_producing'
");
SELECT trees.* , price.10mm , price.20mm FROM trees INNER JOIN price ON
trees.ID=price.treeid where trees.primarycolor like '%' and trees.secondarycolor like '%'
and trees.fallcolor like '%' and trees.droughtresistant like '%' and trees.height like
'%' and trees.spread like '%' and trees.trunkcolor like '%' and trees.flowering like '%'
and trees.fruitproducing like '%'
其中,$var_名称是一个字符串,如红色或绿色、true或false或通配符%
实际打印出来的查询如下:
$result = mysql_query("SELECT trees.*
$bottom_query
FROM trees
INNER JOIN price
ON trees.ID=price.treeid
where trees.primarycolor like
'$primary_color'
and trees.secondarycolor like
'$secondary_color'
and trees.fallcolor like
'$fall_color'
and trees.droughtresistant like
'$drought_resistant'
and trees.height like
'$height'
and trees.spread like
'$spread'
and trees.trunkcolor like
'$trunk_color'
and trees.flowering like
'$flowering'
and trees.fruitproducing like
'$fruit_producing'
");
SELECT trees.* , price.10mm , price.20mm FROM trees INNER JOIN price ON
trees.ID=price.treeid where trees.primarycolor like '%' and trees.secondarycolor like '%'
and trees.fallcolor like '%' and trees.droughtresistant like '%' and trees.height like
'%' and trees.spread like '%' and trees.trunkcolor like '%' and trees.flowering like '%'
and trees.fruitproducing like '%'
我的问题是,即使WHERE子句中有所有通配符,查询也不会返回任何结果。
我使用的是PHP和HTML——不确定是什么版本,很可能是最新版本
我想使用%作为*来选择数据库中任何类型的所有内容
请帮助我,互联网上的好人,荣耀将属于你:D如果没有选择过滤器,根本不要使用WHERE子句。这将在服务器上运行得更快、效率更高,不管怎样,这都是你想要的。让所有查询尽可能简单,以避免在不需要的地方加载。只有在出现错误时才在查询中添加WHERE子句做出选择。不要使用仍然返回所有记录的LIKE子句。根据输入动态构建WHERE子句是一种方法。只需做少量工作,但从长远来看效果会更好
尼克-您是否打算用更具体的内容替换一个或多个类似的子句?否则您根本不需要WHERE子句。哈维,谢谢,我将尝试一下。在通配符之前,这是否返回任何结果?选择trees.*,price.10mm,price.20mm FROM trees内部连接trees上的price。ID=price.treeidMy的目的是让用户从下拉框中选择任意一种颜色,或者选择多种颜色中的一种,并且变量将是fileld,其中%用于选择任意颜色或单词(颜色)如果他们选择了其他方式。Rachel我会尽力让你知道谢谢你,好先生,我会利用这些信息建立一个更好、更有效的查询。非常好的信息。