We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24969
    • 120 Posts
    Hi guys,
    I have a dog kennel that I am currently working on. My question is I have a page showing the current litters, the client would like to have a link at the bottom of the current litter showing pictures of the puppies. Similar to http:\\www.chrys-haefen.com\litters.php?breed=goldens but it would be in modx...

    I have a snippet which gets the sire and dam from the database as follows
    <?php
    if(isset($dogid)) { 
         switch ($dogid)
              case 1000:
                   output = 'Marleys pups';
              break;
    }else{
    $sql="SELECT sireim.filelocation AS sireim_filelocation,
    sireim.description AS sireim_desc,
    sireim.width AS sireim_width,
    sireim.height AS sireim_height,
    damim.filelocation AS damim_filelocation,
    damim.description AS damim_desc,
    damim.width AS damim_width,
    damim.height AS damim_height,
    tbreeding.dow,
    tbreeding.rd,
    tbreeding.no_male_puppies,
    tbreeding.no_female_puppies,
    tbreeding.male_available,
    tbreeding.female_available,
    sire.callname AS sire_callname,
    dam.callname AS dam_callname,
    sire.regname AS sire_regname,
    dam.regname AS dam_regname
    FROM `tblbreeding` tbreeding
    LEFT JOIN `tbldogs` sire ON sire.dog_id = tbreeding.sireFK
    LEFT JOIN `tbldogs` dam ON dam.dog_id = tbreeding.damFK
    LEFT JOIN `tblimages` sireim ON sireim.dogFK = sire.dog_id AND sireim.use_pict = 'Y'
    LEFT JOIN `tblimages` damim ON damim.dogFK = dam.dog_id AND damim.use_pict = 'Y'
    WHERE breedFK = '87'
    LIMIT 0 , 1000";
    $rs=$modx->db->query($sql);
    $resultArray = $modx->db->makeArray($rs);
    
    //var_dump($resultArray);//for debugging
    
    if (count($resultArray)>0){
        $output = '';
         foreach($resultArray as $item){
               //print_r($item);//for debugging
               $params['Sire_callname']=$item['sire_callname'];
               $params['imsire_file location']=$item['sireim_filelocation'];
               $params['salt text']=$item['sireim_desc'];
               $params['swidth']=$item['sireim_width'];
               $params['shieght']=$item['sireim_height'];
               $params['Dam_callname']=$item['dam_callname'];
               $params['imdam_filelocation']=$item['damim_filelocation'];
               $params['dalt text']=$item['damim_desc'];
               $params['dwidth']=$item['damim_width'];
               $params['dhiehgt']=$item['damim_height'];
               $params['Sire_regname']=$item['sire_regname'];
               $params['Dam_regname']=$item['dam_regname'];
               $params['Whelping date']=$item['dow'];
               $params['Release date']=$item['rd'];
               $params['Num male']=$item['no_male_puppies'];
               $params['Num female']=$item['no_female_puppies'];
               $params['Available males']=$item['male_available'];
               $params['Available females']=$item['female_available'];
               $output.=$modx->parseChunk('Golden Litters', $params, '[+', '+]');	
         }	
    	
    }
    }
    return $output;
    

    which would call the chunk Marleys pups
    in that chunk I would have the img tags.

    on my calling page I have
    Pictures are <a href="[~[*id*]~]&dogid=1000">here</a>

    How would you do this... it seems to me that this is the only way I can do it.... but I know that is always another way.
      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
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      How many litters and puppies are we talking about ? Are you talking about a database with thousands of records? If it’s not too many records, I would probably handle this just by relying on MODx’s documents to store the info (I realize that’s not a normalized database solution, but the dev time is WAY less).

      If you have a lot of records, or if you already have this info in a database table, then your Snippet approach is probably the way to go. What I might suggest is that you separate your database query into a separate file and you pass a value to it. Something like :

      <?php
      function your_query($breed_key)   {
        if (!is_int($breed_key)) {
         exit;  // thou shalt validate your user supply data...
        }
        $sql = "SELECT .... WHERE breedFK = '$breed_key';
      
      ... 
      return records...
      
      }
      
      
      ?>



      Then your Snippet can grab the variable from the $_GET array and pass it to the function.

        • 24969
        • 120 Posts
        Thanks everett,
        I am a complete noob with modx, I as still getting my head around the different calls [[]] [**] [!!} {{}} calling a function from a page seems like the way to go.... but I don’t know how to pass a value to a snippet call....

        $dogId=$_REQUEST($dogid);
        print_r($dogId);
        if(isset($dogId)) { 
             switch ($dogId)
             {
                  case 1000:
                       $output = 'Marleys pups';
                       return $output;
                  break;
             }
        }


        With that snippet call I’m getting
        Fatal error: Function name must be a string in /home/chry7248/public_html/modx/manager/includes/document.parser.class.inc.php(770) : eval()'d code on line 2
          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
          • 9207 ☆ A M B ☆
          • 2,475 Posts
          Ahh... your error... I think you meant: $x = $_REQUEST[’value’]; The $_REQUEST is an array, not a function, so it uses [’this’] to identify the spot in the array you’re after.

          Passing values to Snippet calls is easy... the format is sort of a modified CGI type of syntax, e.g.
          [[YourSnippet?&my_variable=`1`]]

          Would call the Snippet named "YourSnippet" and within that code, $my_variable would be set to "1":
          <?php
          
          // YourSnippet
          
          print $my_variable;  // case matters!  It's not $MY_Variable or $mY_Variable -- it must agree w your Snippet parameters
          ?>


          You can nest Snippet calls
          Here’s a couple links:
          http://bobsguides.com/modx-snippets.html -- specifically the bit about Parameters
          http://wiki.modxcms.com/index.php/Snippet_call_anatomy
            • 24969
            • 120 Posts
            Thanks Everette,


              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