We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6316
    • 92 Posts
    That’s my snippet:

    <?php
    $test = $modx->db->query("SELECT * FROM site_site_content WHERE alias = 'about' LIMIT 1");
    print_r ($test);
    ?>
    


    I call it uncached (enclosed in [! !]) but it doesn’t work. It returns the following:

    Resource id #11


    Which is some random page on my site. If I change WHERE alias to something else, the output remains the same. Running the same query in the database itself works fine.

    I’m puzzled. Please help! undecided

    Also, should I use $modx->$db->select for such kind of query?
      • 4310
      • 2,310 Posts
      <?php
      $result = $modx->db->query("SELECT * FROM site_site_content WHERE alias = 'about' LIMIT 1");
      $test = $modx->db->makeArray( $result );
      print_r ($test);
      ?>
      
        • 22303 MODX Staff
        • 10,725 Posts
        Note this is for Evolution...
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          A SELECT query (either using $modx->db->query() or $modx->db->select() will return an object or an array, even if there is only one item to be returned. The object or array then needs to be processed to retrieve individual values. For example, if you know there is only one item returned (best to check for this with a $modx->db->getRecordCount($result) first), you can use $modx->db->getValue($result). If you will have more than one row returned, you can use $modx->db->getRow($result) to iterate through the rows.

          http://wiki.modxcms.com/index.php/API:DBAPI:getRecordCount
          http://wiki.modxcms.com/index.php/API:DBAPI:getValue
          http://wiki.modxcms.com/index.php/API:DBAPI:getRow
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 6316
            • 92 Posts
            Thank you very much!

            Quote from: OpenGeek at Oct 29, 2010, 07:23 PM

            Note this is for Evolution...
            I’ve corrected the topic title smiley