ChronoEngine.com homepage

Forums

a little help for filtering with a search form and where conditions

S
silvered.dragon posted Nov 13, 2019 at 16:34
Hi to all and thank you for this incredible project.
I'm under cc v6 and I want to build a search form for filtering my listings. The point where I'm stuck is under the where conditions rules list box, I can't really understand the sintax:
I have a read data function 'read_disponibilita_ig'
in the where conditions I want to reproduce the following statement where you will notice a first part, that I would like to be always filtered, and a second part with related keywords that I'm using in the search form. I'm trying to understand how to fill the where conditions rules list box:
first part
(
read_disponibilita_ig.input_tratta = Italia-Grecia
AND
read_disponibilita_ig.tipologia_dispo = cabina
)
second part (only if I'm submitting data to the search form)
AND
(
read_disponibilita_ig.input_reference = {data:keywords1}
OR
read_disponibilita_ig.input_date = {data:keywords2}
OR
read_disponibilita_ig.current_name = {data:keywords3}
}
I tried to place those conditions under the dedicated condtion boxes, and this will work but obviously in this way "the basic listing", I mean the one in first part that must not be filtered by the search form, is giving me a not desired list like in the debug, cause is getting the empty value into the search fields.
SELECT COUNT(`read_disponibilita_ig`.`aid`) AS `read_disponibilita_ig.count` FROM `mwfao_chronoforms_data_form_disponibilita` AS `read_disponibilita_ig` WHERE ( `read_disponibilita_ig`.`input_tratta` = 'Italia-Grecia' AND `read_disponibilita_ig`.`tipologia_dispo` = 'cabina' AND `read_disponibilita_ig`.`venduta` = '0' ) AND ( `read_disponibilita_ig`.`input_reference` = '' OR `read_disponibilita_ig`.`input_date` = '' OR `read_disponibilita_ig`.`current_name` = '' );
So the question is how I can make this statement to exclude the second part if I'm not submitting data to the form? I can't understand how to use IF ELSE in the where conditions rule list box, I checked this link for CCv5 that is using pure php but is not working as expected.
http://www.chronoengine.com/faqs/72-ccv5/5215-how-do-i-build-a-where-statement-in-ccv5.html
many thanks
S
silvered.dragon posted Nov 13, 2019 at 17:39
ok I think I made it.. but maybe is a little dirty and I will appreciate if there is a better way to accomplish this, for the moment I fixed in this way mixing php and shortcodes:
[strong]FIRST PART
[/strong]read_disponibilita_ig.input_tratta:Italia-Grecia
AND
read_disponibilita_ig.tipologia_dispo:cabina
SECOND PART
<?php if (null != $this->data('keywords1')) { ?>
AND
read_disponibilita_ig.input_reference:{data:keywords1}
<?php } ?>
<?php if (null != $this->data('keywords2')) { ?>
AND
read_disponibilita_ig.input_date:{data:keywords2}
<?php } ?>
<?php if (null != $this->data('keywords3')) { ?>
AND
read_disponibilita_ig.current_name:{data:keywords3}[br]<?php } ?>
obviously I can add into the if statement others OR ANDS etc in a way that will allow me to search in different fields with the same keyword.
S
shiluba posted Dec 3, 2019 at 05:02
1 Likes
Hi. Did you try to use conditions (not Rules lists) with "Null value" set to "Continue" ?
S
silvered.dragon posted Dec 3, 2019 at 21:44
yes but this is giving me error, anyway the problem here is how to use php in the where box in a correct way without shortcodes, cause the ccv5 similar code
return array('model_id.column' => 'value');
is not working in ccv6
S
shiluba posted Dec 4, 2019 at 14:05
Indeed I do not think this type of code works in CCv6. Either I'd do a Where condition like ...
model_id.column ... = ... "value"  ... Null value : Use / Continue


... or a Rules list like ...

model_id.column/=:value
What says the error message ?
S
shiluba posted Dec 4, 2019 at 14:18
More accurately, I'd do this Where condition ...
model_id.column ... = ... value ... Null value : Use / Continue
(no double quotes around the value)
This topic is locked and no more replies can be posted.

2Checkout.com

2CheckOut.com Inc. (Ohio, USA) is an authorized retailer for goods and services provided by ChronoEngine.com