【发布时间】:2018-10-19 13:02:22
【问题描述】:
我想做一个原则查询,其中每个参数可以有多个值(来自一个选择多个)。
我有一个表,其“类型”参数的值可以是 1、2、3 或 4,而“在线”参数的值可以是 0 或 1。
到目前为止,我的查询如下:
$query = $this->createQueryBuilder('properties');
if (array_key_exists('type', $searchValues)) {
$types = $searchValues['type'];
$iterator = 0;
foreach ($types as $type) {
if ($iterator == 0) {
$query->andWhere('properties.idPropertyType = ' . $type);
} else {
$query->orWhere('properties.onlineProperties = ' . $type);
}
$iterator++;
}
}
if (array_key_exists('status', $searchValues)) {
$status = $searchValues['status'];
$iterator = 0;
foreach ($status as $statu) {
if ($iterator == 0) {
$query->andwhere('properties.onlineProperties = ' . $statu);
} else {
$query->andWhere('properties.onlineProperties = ' . $statu);
}
$iterator++;
}
}
$properties = $query->getQuery()->getResult();
在参数类型 = 1 且在线 = 0 和 1 的搜索的情况下,我得到的结果类型是 1 以外的另一个值。我理解原因,但我无法找出进行查询的正确方法。
【问题讨论】:
标签: doctrine-query