We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 53390
    • 42 Posts
    Hi,
    how can I get multiple matching values from a MIGXdb field:
    Say I have a custom field called "category" and want to print all elements where category has values 5, 7, 9.
    If I pass a single value "5", it's working fine, but how can I get all elements when I need to match multiple values of the same db field?
    &where=`{"category":"5, 7, 9","published":"1"}`


    [[!migxLoopCollection?
    &packageName=`mygallery`
    &classname=`myGallery`
    &sortConfig=`[{"sortby":"pos","sortdir":"ASC"}]`
    &where=`{"category":"5","published":"1"}`
    ]]
    


    Any ideas?
    Thanks.
      • 46886
      • 1,154 Posts
      This page from Susan's cookbook looks useful

      https://modxcookbook.com/add-ons/migx/search-migx-tv-values.html

      HTH
        • 53390
        • 42 Posts
        Thank you nuan88,

        this is a bit too manual data access, also designed for JSON and I am using MySQL so not sure all would work as expected. I could write my own snippet for that but I believe there's a faster and more straightforward way of doing it, basically by using migx built-in special tags.
        I have a working solution for this already - when I multiply the special tag with parameters a number of times with different value each time. But this doesn't look to me like proper way and may result in code being unnecessary long.
          • 46886
          • 1,154 Posts
          Yes I also felt it was not the easiest way. I am just beginning to learn MIGX.

          How about this one from Bruno's github page examples https://github.com/Bruno17/MIGX/wiki/migxLoopCollection

          [[migxLoopCollection? 
              &classname=`modResource`
              &selectfields=`id,pagetitle`
              &where=`{"parent":"3"}`
              &toJsonPlaceholder=`json` 
          ]]
          [[+json]]


          I believe if you change the &where to

          &where=`{"category":"3,5,7"}`


          And I don't think there will be spaces between the values. But I not sure whether it will interpret this as value= 3 OR 5 OR 7, which is what we want.
            • 46886
            • 1,154 Posts
            Also I would suggest stripping your code down to the bone. The &sortConfig value is not useful yet, let's get the right output first.
              • 53390
              • 42 Posts
              I don't use JSON and will not to use it. I am not a fan of this technology which feels to me like 30 years old. smiley If I tried JSON with 500,000+ data records and 10-20k users accessing it every day and downloading images and videos on top of that, I think I'd kill the server and would get kicked out quickly.
              That's why I stay away from such libraries like jQuery as much as I can. Every day, I knock on websites that takes 2-3 minutes to download when my Windows loads in 2-3 seconds. Very often I quit websites if they're not loaded in 5 seconds. I don't know what techs or libs they use but this is not acceptable to me so I think to my visitors on my websites as well.

              As I said already, single value is working fine and I tried very different ways to pass multiple values but with no luck.
                • 4172
                • 5,888 Posts
                try this:

                &where=`{"category:IN":[5,7,9],"published":"1"}`
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 53390
                  • 42 Posts
                  Thank you Bruno.
                  This is working fine now.
                    • 53390
                    • 42 Posts
                    Is there any calling format for strings, say for example, if a field "members" has multiple values in one cell "Tom, James, John". And I want to get record by passing only one or only two of them. Like in SQL query:
                    SELECT * FROM members WHERE team01 LIKE "%Tom% or %John%";
                      • 46886
                      • 1,154 Posts
                      you may want to ask this in a new thread so its noticed by Bruno, but my luck in this thread has been poor wink