We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1331
    • 129 Posts
    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.
      • 4172
      • 5,888 Posts
      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.]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 4172
        • 5,888 Posts
        for multiple ids do

        mysite.com/?ids=1,2,3


        and

        &where=`{"id:in":"[[!getReqParam? &name=`ids`]]"}`
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 1331
          • 129 Posts
          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.
            • 1331
            • 129 Posts
            I see, the value has to be in an array bracket like
            {"id:IN":[78]}


            Therefore, I had to write it like
            {"id:IN":[ [[!getReqParam? &name=`ids`]] ]}


            Now just need to figure out how to create a comma delimited query string. [ed. note: ambaxter last edited this post 10 years, 8 months ago.]
              • 4172
              • 5,888 Posts
              ah, sorry, I was thinking, you had talked about getImageList.
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 4172
                • 5,888 Posts
                where do you get the ids from for the query-params?
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 1331
                  • 129 Posts
                  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.
                    • 1331
                    • 129 Posts
                    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.
                      • 4172
                      • 5,888 Posts
                      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]] ]}`
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!