We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30379
    • 5 Posts
    Hi!

    When I had MODx evolution, I used following code to get information from the database:
    <?php
    $haku = mysql_query( "SELECT id, pagetitle, parent, description, content FROM `revo_site_content` WHERE `parent`=3 ORDER BY `id` DESC  LIMIT 2");
    
    while ( $tiedot = mysql_fetch_array ( $haku ) )
    {
    
    }
    ?>
    


    When I installed the MODx Revolution, this code doesn’t work anymore. I read that with the Revolution I have to use some ORM or xPDO thing but I have no idea how to use them... And haven’t found anythind easy enough for me. So could you help me with that? How I can get those information from my MySQL database with the Revolution?

    Thank you! smiley
      • 3749
      • 24,544 Posts
      Revolution uses xPDO. Here’s an example that should get you started:

      <?php
      $c = $modx->newQuery('modResource');
      $c->select(array('id', 'pagetitle', 'parent', 'description', 'content'));
      
      $c->where(array(
         'published'=>'1',
         'deleted'=>'0',
         'parent'=>'3',
      ));
      
      $c->sortby('id', 'DESC');
      
      $docs = $modx->getCollection('modResource', $c);
      
      foreach ($docs as $doc) {
          $output .= '<br />Title:' . $doc->get('pagetitle') . ' ID:' . $doc->get('id') .'<br />';
      }
      return $output;

        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 30379
        • 5 Posts
        Thanks a lot! That was very helpful smiley

        How I can set a limit for the articles that the script will show? I want to print only two newest articles at a time.
          • 3749
          • 24,544 Posts
          $c->limit(2);


          This would get the next 10 starting with the third one.
          $c->limit(10,2);


          :)
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 30379
            • 5 Posts
            Thank you! laugh