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
    Hope someone out there can give me a hand. I'm new to Modx...

    Anyway. I want to count resources that has a specific tv-value. I have tried every solution in the Forums but non works.

    A straight SQL query would look as following, how do I do it in Modx to get the result?

    Thank's in advance!


    <?php
    $query = 'SELECT COUNT(value) FROM `mod_site_tmplvar_contentvalues` WHERE `value` = \stockholm\' AND `tmplvarid` =71';
    $result = mysql_query ($query);
    $row = mysql_fetch_array ($result, MYSQL_NUM);
    $total = ''.$row[0].'';
    echo $total;
    ?>
      • 16348
      • 64 Posts
      Try something like this:
      $total = $modx->getCount('modTemplateVarResource', array(
         'value' => 'stockholm',
         'tmplvarid' => 71,
      ));
      $modx->setPlaceholder('total', $total);
      
        • 813 ☆ A M B ☆
        • 326 Posts
        This isn't directly related, but Mark Hamstra has an explanation of getCount in his blog post on prepping snippets for getPage: http://www.markhamstra.com/modx-blog/2011/12/preparing-custom-snippets-for-getpage/. That helped me a lot in understanding how it works.
          • 19115
          • 20 Posts
          Thank's guys!

          Still don't get it to work. Great if some modx guru out there could give a hand smiley
            • 4041
            • 788 Posts
            It will be much easier to help if we know what version of MODx are you using, Evolution or Revolution?
              xforum
              http://frsbuilders.net (under construction) forum for evolution
              • 19115
              • 20 Posts
              Yo. Revo 2.1.5