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

    I run getSources this way:

     $options = array(
        "resources" => join(",",$ids),
        "includeTVs" => "1",
        "tpl" => "referenceRow"
      );
      print $modx->runSnippet('getResources', $options);


    $ids is an Array of ids. After joining it as a comma separated list of ids which, when echoed, is as expected. (eg. "1,5,19");

    But when executed i get this error:

    [2010-12-22 14:56:45] (ERROR @ /index.php) Error 42000 executing statement: Array ( [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 '1,2,15,18,27,23,30,3,4,22,24,26,5,6,7,8,9,10,11,12,14,13,17,16,19,20,21,25,33,34' at line 1 )


    Anyone an idea what is happening here?

    Thanks in advance.


    UPDATE: This post with more information is now also on StackOverflow:
    http://stackoverflow.com/questions/4603593/getresources-snippet-with-specified-resourceids-does-not-work
      Worker at vortrieb.net - B
      • 21555
      • 10 Posts
      Still having this issue. :/
        Worker at vortrieb.net - B
        • 22303 MODX Staff
        • 10,725 Posts
        Quote from: nils_r at Dec 22, 2010, 08:01 AM

        $ids is a comma separated list of ids which, when echoed, is as expected. (eg. "1,5,19");
        If $ids is a comma separated list of ids already, why are you join()’ing it? I think that might be your problem.
          • 21555
          • 10 Posts
          Quote from: OpenGeek at Jan 03, 2011, 09:16 AM

          Quote from: nils_r at Dec 22, 2010, 08:01 AM

          $ids is a comma separated list of ids which, when echoed, is as expected. (eg. "1,5,19");
          If $ids is a comma separated list of ids already, why are you join()’ing it? I think that might be your problem.

          Sorry, of course i meant that $ids is an array of ids, and when echoed with the join() it’s as expected. Of course, if $ids was already a string join() would warn me because of the invalid arguments. Also it does not work when hardcoding the ids eg:

           $options = array(
              "resources" => "33,34",
              "includeTVs" => "1",
              "tpl" => "referenceRow"
            );
            print $modx->runSnippet('getResources', $options);

            Worker at vortrieb.net - B
            • 21555
            • 10 Posts
            This is the whole code:

            <?php
            $resource_ids = $modx->getTree(27,1); # => 27 is the Container with the desired resources
            # We need the 'Kategorie'-TV of the resources
            $cat = $modx->getObject('modTemplateVar', array('name' => 'Kategorie'));
            
            # Map Resources to Category
            $resources_by_cat = array();
            foreach ($resource_ids as $id) { 
              $resources_by_cat[$cat->getValue($id)][] = $id; 
            }
            
            # Iterate over categories and output the resources
            foreach ($resources_by_cat as $cat => $ids) {
              $joined_ids = join(",",$ids); # => eg "33,34,56"
              print "<h2>".$cat."</h2>";
              print '<table class="references">';
              print '
                <tr>
                  <th class="title">Titel</th>
                  <th class="author">Von</th>
                </tr>
                ';
              print $modx->runSnippet('getResources', array(
                "resources" => $joined_ids,
                "includeTVs" => "1",
                "tpl" => "referenceRow"
              ));
              print '</table>';
            }
            ?>
            

            Also on stackoverflow: http://stackoverflow.com/questions/4603593/getresources-snippet-with-specified-resourceids-does-not-work
              Worker at vortrieb.net - B
              • 21555
              • 10 Posts
              It works when using the classic modx snippet syntax [[…]] instead of $modx->runSnippet();
                Worker at vortrieb.net - B