⚠️ Urgent! Active Attacks on MODX Revolution Sites Below Revolution 2.6.5
Subscribe: RSS
  • 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
    • 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;

        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
      • 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.
        • $c->limit(2);


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


          :)
            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
          • Thank you! laugh