【发布时间】:2015-11-18 07:40:34
【问题描述】:
我的网站网址如下所示:
http://example.com/realestate/type-apartament/rooms-3-2/key-value1-value2-value3
所以从这里我得到一个这样的数组:
[type] => Array
(
[0] => apartament
)
[rooms] => Array
(
[0] => 3
[1] => 2
)
[key] => Array
(
[0] => value1
[1] => value2
[2] => value3
)
我从 db 中的选择应该如下所示:
Select * from properties a
LEFT JOIN properties_type b
ON a.property_type_id = b.property_type_id
WHERE b.property_type = apartament
AND a.rooms = 3 AND a.rooms = 2
如何根据我拥有的键值生成此选择?我唯一想到的解决方案是使用每个键和相应的表、外键、列创建一个数组助手......
这是我处理来自 url 的过滤器的函数:
if(!function_exists('process_filters')) {
function process_filters($filters) {
$data = array();
foreach($filters as $filter):
$filter_exploded = explode('-', $filter);
$val = array_shift($filter_exploded);
$data[$val] = $filter_exploded;
endforeach;
return $data;
}
}
$filters 来自控制器方法的地方:
public function index(...$params)
【问题讨论】:
-
不确定我了解您的了解程度,您有包含值的数组吗?或者是什么?您能否向我们展示您已经取得了多远/您尝试了什么的代码?
-
我编辑了我的代码,请检查
标签: php mysql codeigniter activerecord