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

    I’m a MODx noob, and have a couple of sites up and running very well. The more I learn, the more I love this system. Unfortunately, I have a few things that I *know* the system must be able to do, but after tons of searching and goolging, reading wikis, etc. I haven’t yet figured out. I know how to do many of these things in perl (my native computer language), but I’d like to keep everything in MODx if possible.

    I would like to display information as contained in a mysql database based on something added to the URL. So, for example, www.example.com/index.php?item=abc123 . How do I retrieve the value for "item" and use it in a chunk, for example?

    Also, I would love to be able to have more flexibility with displaying my data than what I currently have with the datagrid widget. I’m sure there IS a way to do this, but need to be pointed in the right direction. I’m guessing it has to do with chunks and ditto, but I really have no idea.

    Thanks.
      • 25663 MODX Staff
      • 12,272 Posts
      From the datagrid perspective, look at the maketable class helper in the resources section.
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 4041
        • 788 Posts
        This example of grabbing a parameter and querying the database may give you a bit of insight hopefully...

        lets say you have a url like this:
        www.mydotcom.com/blog.html?blogid=23

        <?php
        //===== check if a chunk was sent in the params for the blogpost
        $blogchunk = isset($_GET['blogchunk']) ? $_GET['blogchunk'] : "BlogPost_modx";
        // set up a placeholder for message if no entries are found
        $modx->setPlaceholder('noentriesfound', 'No Entries Found'); // [+noentriesfound+]
        $output ="";
        // if the param is not empty then set up the Where part of the sql
        if($_GET['blogid'] !=""){
          $where_1 ="WHERE id=".$_GET['blogid'];
        }
        
        $sql = "SELECT *
        FROM ".$site_content."
        ".$where_1;
        
        $result = $this->dbQuery($sql);
        $resource = array();
            for($i=0;$i<@$this->recordCount($result);$i++)  {
              array_push($resource,@$this->fetchRow($result));
            }
        // count the number of entries
        $limit = count($resource);
        
        // if the number or entries is less than 1 tell them
        if(!$result) {
           $output .= "[+noentriesfound+]";
        }
        
        // print the results
        if($limit>0) {
            for ($x = 0; $x < $limit; $x++) {
        
               $blogcontent = $resource[$x]['content'];
               $createdon = strftime("%m-%d-%y %H:%M:%S", $resource[$x]['createdon']);
               $publishedon = strftime("%m-%d-%y %H:%M:%S", $resource[$x]['publishedon']);
        
        // set up the array of placeholders
                 $blogArray = array(
                                   'blogcontent'    => $blogcontent,
                                   'blogid'           => $resource[$x]['id'],
                                   'longtitle'        => $resource[$x]['longtitle'],
                                   'createdon'      => $createdon,
                                   'publishedon'  => $publishedon
                                   ); 
        // this creates your placeholders from the $blogArray and outputs the chunk $blogchunk
        $output .= $modx->parseChunk($blogchunk, $blogArray, '[+', '+]');
          } // end for loop
        return $output;
        ?>


        sorry if this is a bit confusing, I pulled it from one of my larger scripts but I think you can get the general jist of it...
        if you want to see the whole shebang look here: http://frsbuilders.us/frsblogcode.html
        (my dev site so 99% there is in dev stage so excuse the mess... smiley )
          xforum
          http://frsbuilders.net (under construction) forum for evolution
          • 32756
          • 25 Posts
          Quote from: rthrash at Jun 01, 2007, 09:48 PM

          From the datagrid perspective, look at the maketable class helper in the resources section.

          Thanks. I’ve downloaded "maketable" and will have a look at it.

          Does it work with 0.96?

            • 32756
            • 25 Posts
            Quote from: breezer at Jun 01, 2007, 11:48 PM

            This example of grabbing a parameter and querying the database may give you a bit of insight hopefully...

            lets say you have a url like this:
            www.mydotcom.com/blog.html?blogid=23

            <code not quoted>

            I’m going to play around with this and see what I might be able to figure out. Thanks for this.