So, I have a very specific situation where I'm passing a parameter to a query string multiple times like:
mysite.com/?id=1&id=3&id=8
And on the results page, I have migsLoopCollection running a query on a db table.
I want to include a where clause that uses the query to decide which rows to show based on the IDs passed thru the query.
How would I write may where clause? I've tried &where=`{"id:=":[[+id]]}` to no avail.
You can't use the same request-param multiple times.
Each request-param has to be unique.
you can use the getReqParam - snippet to get the request-param
&where=`{"id:=":"[[!getReqParam? &name=`my_id`]]"}`
or fastField - tags, if you have installed fastField or pdoTools
[ed. note: Bruno17 last edited this post 10 years, 8 months ago.]
for multiple ids do
and
&where=`{"id:in":"[[!getReqParam? &name=`ids`]]"}`
Thanks for the tip about getReqParam, Bruno.
When I try using "id:IN" it returns nothing no matter what the query is... Even when the query is just one value. But when I use a single query with "id:=" it works as expected.
ah, sorry, I was thinking, you had talked about getImageList.
where do you get the ids from for the query-params?
They are being created by a series of checkboxes on a previous page. When the user submits his choices to this page, the loop should only return the items that were checked.
I have an idea to use JavaScript to simply gather all the checked values into a hidden field as a comma separated list and then send the hidden field to the query as one item.
you could have your checkboxes as array
<input type="checkbox" name="ids[]" value="1" />
<input type="checkbox" name="ids[]" value="2" />
<input type="checkbox" name="ids[]" value="3" />
and have snippet at the landing-page 'getids':
$ids = $modx->getOption('ids',$_REQUEST,array());
$sanit_ids = array();
if (is_array($ids)){
foreach ($ids as $id){
$sanit_ids[] = (int) $id;
}
}
return implode(',',$sanit_ids);
then use
&where=`{"id:IN":[ [[!getids]] ]}`