properties_tbl:
properties_tbl:
id property_type usd_price euro_price published
----------------------------------------------------
1 private 1000.00 0 yes
2 landed 1200.00 0 yes
3 private 0 1200.00 yes
4 land 2000.00 0 yes
5 land 0 3000.00 yes
6 private 0 1200.00 yes
This table is sample table for my website
此表是我网站的示例表
if usd_price exist euro will 0 and then if euro exist usd price will 0,
如果usd_price存在欧元将为0然后如果欧元存在usd价格将为0,
I made same exchange value usd and euro price in my system.
我在我的系统中做了相同的交换价值usd和欧元价格。
My problem is at searching, when I search like these query it show all rows
我的问题在于搜索,当我搜索这些查询时它会显示所有行
SELECT *
FROM (`properties_tbl`)
WHERE (euro >= 100 OR usd >= 110)
AND (euro <= 5000 OR usd <= 4500)
AND `published` = 'yes'
2 个解决方案
#1
0
I believe the issue is due to your SELECT query, not CodeIgniter's Active Record. The first condition in your WHERE clause is always true, based on the data in your sample table. The comment from devpro is correct, in terms of how you should structure the basic query.
我认为问题是由于您的SELECT查询,而不是CodeIgniter的Active Record。根据示例表中的数据,WHERE子句中的第一个条件始终为true。就构建基本查询的方式而言,devpro的评论是正确的。
To do that in CodeIgniter's Active Record structure, you could likely do it a few different but this works:
要在CodeIgniter的Active Record结构中执行此操作,您可能会做一些不同但这可行:
$this->db->select('*');
$this->db->from('properties_tbl');
$this->db->where('euro BETWEEN 100 AND 5000');
$this->db->where('usd BETWEEN 110 AND 4500');
Hope this helps.
希望这可以帮助。
#2
0
Thanks to everyone , All give me very useful advise. I created new query base on @devpro and @cfnerd.
感谢大家,All给了我非常有用的建议。我在@devpro和@cfnerd上创建了新的查询。
$this->db->where("(property_price BETWEEN $minprice AND $maxprice OR usd BETWEEN $usd_minprice AND $usd_maxprice)");
Now It work! Thanks to all
现在它工作!谢谢大家
#1
0
I believe the issue is due to your SELECT query, not CodeIgniter's Active Record. The first condition in your WHERE clause is always true, based on the data in your sample table. The comment from devpro is correct, in terms of how you should structure the basic query.
我认为问题是由于您的SELECT查询,而不是CodeIgniter的Active Record。根据示例表中的数据,WHERE子句中的第一个条件始终为true。就构建基本查询的方式而言,devpro的评论是正确的。
To do that in CodeIgniter's Active Record structure, you could likely do it a few different but this works:
要在CodeIgniter的Active Record结构中执行此操作,您可能会做一些不同但这可行:
$this->db->select('*');
$this->db->from('properties_tbl');
$this->db->where('euro BETWEEN 100 AND 5000');
$this->db->where('usd BETWEEN 110 AND 4500');
Hope this helps.
希望这可以帮助。
#2
0
Thanks to everyone , All give me very useful advise. I created new query base on @devpro and @cfnerd.
感谢大家,All给了我非常有用的建议。我在@devpro和@cfnerd上创建了新的查询。
$this->db->where("(property_price BETWEEN $minprice AND $maxprice OR usd BETWEEN $usd_minprice AND $usd_maxprice)");
Now It work! Thanks to all
现在它工作!谢谢大家