We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24969
    • 120 Posts
    The following snippet will not work, how do you debug your snippets?
    <?php
    $output = '';//create variable for holding the output
    $sql = $modx->db->query( 'SELECT * FROM `tblbreeding` where breedFK = '87' LIMIT 0 , 1000');//define the DB query, in this case the table is named 'tblbreeding' golden breedid is 87
    $resultArray = $modx->db->makeArray($sql);//put it into an array
    foreach($resultArray as $item) //go through each record in the array
    {//start looping through the data array
    $param['sire']=$item['sireFK'];//set the placeholders, the $params sets the name of the placeholder, the $item is the field name from the DB table
    $param['dam']=$item['damFK'];//store the dams fk
    }//finish looping through the data array
    $sire = $modx->db->query( 'SELECT callname FROM tbldogs WHERE dog_id ='$param['sire']);
    $dam= $modx->db->query( 'SELECT callname FROM tbldogs WHERE dog_id ='$param['dam']);
    $sire = $modx->db->makeArray($sire);//put it into an array
    $dam =$modx->db->makeArray($dam);//put it into an array
    foreach($resultArray2 as $item2)
    {
    $params['sire']=$item['callname'];
    $output.=$modx->parseChunk('Golden Litters', $params, '[+', '+]');//define the chunk name and process the content
    }
    return $output;//now return the output from the processed chunk
    ?>
      The important thing is not to stop questioning. Curiosity has its own reason for existing. One cannot help but be in awe when he contemplates the mysteries of eternity, of life, of the marvelous structure of reality. It is enough if one tries merely to comprehend a little of this mystery every day. Never lose a holy curiosity.

      -Albert Einstein (1879 - 1955)

      Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8e-fips-rhel5 DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
      • 4172
      • 5,888 Posts
      Try this:

      <?php
      
      
      $sql="
      SELECT tr.*,sire.callname as sire_callname,dam.callname as dam_callname FROM `tblbreeding` tr 
      left join `tbldogs` sire on sire.dog_id = tr.sireFK
      left join `tbldogs` dam on dam.dog_id = tr.damFK
      where breedFK = '87' LIMIT 0 , 1000
      ";
      
      $rs=$modx->db->query($sql);// had forgotten this line, sorry
      $resultArray = $modx->db->makeArray($rs);
      
      //print_r($resultArray);//for debugging
      
      if (count($resultArray)>0){
      $output = '';
      foreach($resultArray as $item){
      	
      //print_r($item);//for debugging	
      	
      $output.=$modx->parseChunk('Golden Litters', $item, '[+', '+]');	
      }	
      	
      }
      return $output;
      
      ?>
      
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 24969
        • 120 Posts
        Query works good... but I get the following error when executing on a page.
        Parse error: parse error in E:\wamp\www\Chrys-haefen\manager\includes\document.parser.class.inc.php(770) : eval()'d code on line 17
          The important thing is not to stop questioning. Curiosity has its own reason for existing. One cannot help but be in awe when he contemplates the mysteries of eternity, of life, of the marvelous structure of reality. It is enough if one tries merely to comprehend a little of this mystery every day. Never lose a holy curiosity.

          -Albert Einstein (1879 - 1955)

          Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8e-fips-rhel5 DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
          • 4172
          • 5,888 Posts
          ah, sorry must be:

          $resultArray = $modx->db->makeArray($rs);
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 24969
            • 120 Posts

            ah, sorry must be:

            $resultArray = $modx->db->makeArray($rs);
            Ok thanks, why when I remove the comment from the debugging statement do I get this error.
            Parse error: parse error in E:\wamp\www\Chrys-haefen\manager\includes\document.parser.class.inc.php(770) : eval()'d code on line 19

            It happens when I remove any one or both od the debugging statments
            <?php
            $rs="
            SELECT tr.*,sire.callname as sire_callname,dam.callname as dam_callname FROM `tblbreeding` tr 
            left join `tbldogs` sire on sire.dog_id = tr.sireFK
            left join `tbldogs` dam on dam.dog_id = tr.damFK
            where breedFK = '87' LIMIT 0 , 1000
            ";
            
            
            
            $resultArray = $modx->db->makeArray($rs);
            
            print_r($resultArray);//for debugging
            
            if (count($resultArray)>0){
            $output = '';
            foreach($resultArray as $item){
            	
            print_r($item)//for debugging	
            	
            $output.=$modx->parseChunk('Golden Litters', $item, '[+', '+]');	
            }	
            	
            }
            return $output;
            ?>


            How do you debug a snippet with out having to create a test environment?

            My document currently shows nothing when viewed. I knowticed that you didn’t specify what was going to be output. is that why??


            Complete noob here, (incase you could tell)
              The important thing is not to stop questioning. Curiosity has its own reason for existing. One cannot help but be in awe when he contemplates the mysteries of eternity, of life, of the marvelous structure of reality. It is enough if one tries merely to comprehend a little of this mystery every day. Never lose a holy curiosity.

              -Albert Einstein (1879 - 1955)

              Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8e-fips-rhel5 DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
              • 10487 MODX Staff
              • 1,535 Posts
              There is a missing semi-colon on the second debug line which could be causing the error, this line:
              print_r($item)//for debugging

              Should be:
              print_r($item); //for debugging
                Garry Nutting
                Senior Developer
                MODX, LLC

                Email: [email protected]
                Twitter: @garryn
                Web: modx.com
                • 24969
                • 120 Posts
                Now I feel really stupid.... Thanks garryn.

                The array returns nothing.... I.E. it has a count of 0.... Yet when I execute the query in phpmyadmin it return two rows.
                  The important thing is not to stop questioning. Curiosity has its own reason for existing. One cannot help but be in awe when he contemplates the mysteries of eternity, of life, of the marvelous structure of reality. It is enough if one tries merely to comprehend a little of this mystery every day. Never lose a holy curiosity.

                  -Albert Einstein (1879 - 1955)

                  Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8e-fips-rhel5 DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635