We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19115
    • 20 Posts
    Hi guys
    I'm going mental here. Anyone know how to pass a longtitle value to a select binding instead of using a static value;

    @SELECT COUNT(*) FROM mod_site_tmplvar_contentvalues WHERE value LIKE '***here I would like to pass longtitle value***'

    Or if there is a way to get getResources to count how many resources that has a specific value in the output.

    I'm building a restaurant site that has a sidebar that list different categories, like budget restaurants, exklusive restaurants etc. What I would like to do is simply to show how many restaurants that are in each category; ex Budget (44), Exclusive (45) etc.

    Really apreciate all help!
    Thank's
    Michael



      • 19369
      • 1,098 Posts
      Try getChildCount snippet.
        • 19115
        • 20 Posts
        Hi man. Thank's!

        However Get childCount wont work.

        For example, a specific restaurant can be exklusive, serve asian food, be based in France, in paris and in a specific part of the city. @Select count as below works, but the problem is that I need to pass the "LIKE-value" dynamicallyl

        @SELECT COUNT(*) FROM mod_site_tmplvar_contentvalues WHERE value LIKE '***here I would like to pass longtitle value***'



          • 9102 ☆ A M B ☆
          • 318 Posts
          Not MODX-specific, but you could do this with JS several different ways.

          You could write a snippet to do it, by getting the objects that match the query (with getMany) and counting the length of the resulting array, and then pass the dynamic value into the snippet.

          However, you may be right that the simplest way to do it would be to use getResources. Seems like it might be a bit of a waste of server cycles, but I think it would work.

          getResources has a parameter called idx which increments with each resource returned. So you could just use the exact same getResources call that you use to generate the actual list. Use a completely blank template for the tpl parameter, and use a template containing only idx for the tplLast.

          Then the only thing that would be returned would be the idx of the last matching resource, which should equal your resource count.

          Does that make sense? I could expand on the first two ideas more if you like...
            • 22019
            • 390 Posts
            I've used the extra tagLister to produce exactly the output you want - the only difference is that I retrieved all values for that TV and included the count.

            getResources does have a total count & use where criteria, but it would need to be called multiple times.
              Writer > E-consultant > MODx developer || Salesforce || modx 2.x || PHP 5.2.13 || MySQL client 5.0.86
              • 19115
              • 20 Posts
              :) thank's guys!
              Don't seam to get it to work though. Superthankful for some extended help smiley

              The test page is on the address below.

              http://www.minakrogar.nu/test1.html
                • 9102 ☆ A M B ☆
                • 318 Posts
                I would have to see the getResources call you're using to give you exact code. odeclas is right, you'll have to call getResources twice: once to generate the list, and once to generate the count. You should use the exact same parameters for both calls except the templates. Use these templates:

                &tpl = `blankTpl`
                &tplLast = `idxTpl`
                


                Where the template blankTpl is completely empty, and idxTpl looks like this:

                [[+idx]]
                
                  • 19115
                  • 20 Posts
                  Great man! I'l try it tmr.

                  Cheers!!!!
                    • 19115
                    • 20 Posts
                    Hi freejung
                    I tried the way you suggested but the result is not right.

                    If you look at the test page on the address below you see that the result doing it the way you suggest shows how many child's each category has. What I need however is to display how many restaurants that are connected to each child. For example how many restaurants that are exklusive, how many that serves asian food, how many restaurants that are based in Stockholm etc, etc.

                    http://www.minakrogar.nu/test1.html

                    These values are saved as TV's on each restaurant and each restaurant will have values from every category. That is; a restaurant can be exclusive AND serving Asian food AND be based in Stockholm AND in the neighborhood called "Vasastan" etc.

                    The best way I think would be to do a snippet that simply count how many instances each cateogry has (city, food etc.). As I'm not very good at PHP so I don't know how to do this though.

                    I tried with the @SELECT call below which simply counts how many instances each category has and which works fine. The problem though is that I have to hard code the LIKE value for each and every category which wont work. Basically I need to find a way to get the LIKE value putted in dynamically.

                    If you know how to do this I would be more than greatful!

                    *** The select call ***
                    @SELECT COUNT(*) FROM mod_site_tmplvar_contentvalues WHERE value LIKE '***here I would like to pass the value dynamically instead of hard code it like ex. Exklusive***'





                      • 22019
                      • 390 Posts
                      Have you tried tagLister? It counts the number of entries in a specific TV - it doesn't have to be a tag.
                      http://rtfm.modx.com/display/ADDON/tagLister

                      You might also be interested in:
                      http://www.learnerdesign.com/news/2011/12/31/filter-results-by-multiple-tags-with-jquery/
                        Writer > E-consultant > MODx developer || Salesforce || modx 2.x || PHP 5.2.13 || MySQL client 5.0.86