pdoTools AND OR
I've got 3 TV's per resource and each TV is multi-select.
In pdoTools tvFilters I want to say
if (TV1 = a or b) AND (TV2 = red or blue) AND (TV3 = 5 or 6 or 7)
but it seems I can not say AND before OR. I have to say OR first?
In pdoTools tvFilters I want to say
if (TV1 = a or b) AND (TV2 = red or blue) AND (TV3 = 5 or 6 or 7)
but it seems I can not say AND before OR. I have to say OR first?
Комментарии: 3
No need to use &tvFilters, it is not getResources:
You will get this:
[[!pdoResources?
&parents=`0`
&select=`id,pagetitle`
&includeTVs=`tv1,tv2,tv3`
&where=`["((tv1 IN ('a','b')) AND (tv2 IN ('red','blue')) AND (tv3 IN ('5','6','7')))"]`
&showLog=`1`
]]
You will get this:
... WHERE ( ((`TVtv1`.`value` IN ('a','b')) AND (`TVtv2`.`value` IN ('red','blue')) AND (`TVtv3`.`value` IN ('5','6','7'))) AND `modResource`.`published` = 1 AND `modResource`.`deleted` = 0 ) ...
Great. Thanks for your help.
But my TV's are multi-select so the data stored is a||b so
I could do
But my TV's are multi-select so the data stored is a||b so
((`TVtv1`. `Value` IN ('a', 'b'))
doesn't work.I could do
('a' IN (`TVtv1`. `Value`)) OR ('b' IN (`TVtv1`. `Value`))
or is there a shorter way to write this?
This is now working with like. I know my code is not elegant but
$thisFilter = array();
$getFilters = array('rabenefit','racollateral','ralanguage','ralob','rasector');
foreach( $getFilters as $filterkey=>$filtervalue) {
if(isset($_GET[$filtervalue])) {
$getParam = $_GET[$filtervalue];
$getParam2 = '';
foreach( $getParam as $key=>$value) {
$thisValue = $modx->sanitizeString($value);
$getParam2 .= "(`TV$filtervalue`.`value` LIKE '%$value%')";
if ($key <> count($getParam)-1) $getParam2 .= " OR ";
}
$thisFilter[] = "($getParam2)";
}
}
Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.