We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3232
    • 380 Posts
    I am looking to setup a TV with the SELECT binding in order to list the first two levels of the tree.

    MySQL isn't my strong suite but I have started with attempting to get the first level to display with unintended results.

    My query is:

    @SELECT pagetitle,id FROM `modx_site_content` WHERE page.parent='0'


    But a lot of items that are on the first level don't show up. Would there be any easy way to display the first two levels?
      • 4172
      • 5,888 Posts
      you can try
      @EVAL return $modx->runSnippet('getResourceList');


      with a snippet like that:

      <?php
      
      $ids = $modx->getChildIds(0,2,array('context' => 'web'));
      $c = $modx->newQuery('modResource');
      $c->sortby('pagetitle','ASC');
      $c->where(array('id:IN'=>$ids));
      if ($collection = $modx->getCollection('modResource',$c)){
          foreach ($collection as $object){
              $options[] = $object->get('pagetitle').'=='.$object->get('id');
          }
      }
      
      return implode('||',$options);
      
      ?>
      
      [ed. note: Bruno17 last edited this post 14 years, 5 months ago.]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 3232
        • 380 Posts
        Thank you Bruno for trying to help out. I am still getting some strange results. See screenshots below. Would show in menu affect this at all?

        I actually see the following in the error log.

         [0] => 42000
            [1] => 1064
            [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE ``.`id` IN ('1','7','8','2','11','12','13','14','15','16','4','5','6','3')' at line 1
        [ed. note: betoranaldi last edited this post 14 years, 5 months ago.]
          • 4172
          • 5,888 Posts
          there was a typo in $c = $modx->newQuery('modResource');

          now try it again.
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 3232
            • 380 Posts
            something is still off. the snippet is not outputing anything. I placed the getResourceList snippet on a page and it is blank.
              • 4172
              • 5,888 Posts
              sorry, there was another little bug in the snippet.
              But now it should do it.
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 3232
                • 380 Posts
                Bruno, no need to be sorry, you have been a great help and didn't have to do any of it.

                This latest iteration works great. Thank you so much for your help. I spent at least two days trying to get @SELECT to do what I wanted it to do.

                -Brian