We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25551 ☆ A M B ☆
    • 1,231 Posts
    Hi folks, I need some help with a snippet I’m creating...  I want to fetch info from a table in my database and it display it on a page but I want the info for a given user to be display on a page.  The code below fetches the info that I need but it’s displaying each ingamename1 table.  How could I alter this code to pull info relative to the internalKey table in modx_web_user_attributes_extended so it display for that page author.  I am a total novice at php and I found this code on the wiki and altered it.


    <?php
    $output = '';
    $sql = $modx->db->query( 'SELECT * FROM `modx_web_user_attributes_extended` LIMIT 0, 1000');
    $resultArray = $modx->db->makeArray( $sql );
    foreach($resultArray as $item)
    {
    $params['id']=$item['id'];
    $params['ingamename1']=$item['ingamename1'];
    $output.=$modx->parseChunk('ingamename1', $params, '[+', '+]');
    }
    return $output;
    ?>


    I also need help with this TV code... I want internalKey to be relative to the author of the document that has the TV in it. I tried =([*id]) and =([*createdby*]) but they didn’t work.
    @SELECT gametitle1 FROM modx_web_user_attributes_extended WHERE internalKey = 97;
      Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
      AugmentBLU - MODX Partner

      BLUcart - MODX Revolution E-Commerce & Shopping Cart
      • 3749
      • 24,544 Posts
      Your first query needs a WHERE clause. $modx->documentObject[’createdby’] will give you id of the page creator which you can then use in your query’s WHERE clause.

      For your second question, I think you’d need a snippet because I don’t think there’s a way to access the page creator’s id in the @SELECT (I could be wrong).

      But, isn’t the modx_web_user_attributes_extended table created and maintained by WebLoginPE?  There ought to be a way to do what you want by just calling WLPE with the proper tpl. You might ask in the WLPE forum.

        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 25551 ☆ A M B ☆
        • 1,231 Posts
        Being able to access the createdby would of solved my problem...

        How could I make this SELECT in to a snippet so that it uses the createdby id?

        @SELECT gametitle1 FROM modx_web_user_attributes_extended WHERE internalKey = [*createdby*];

        Thanks
          Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
          AugmentBLU - MODX Partner

          BLUcart - MODX Revolution E-Commerce & Shopping Cart
          • 33992 ☆ A M B ☆
          • 455 Posts
          $sql = $modx->db->query( 'SELECT gametitle1 FROM modx_web_user_attributes_extended WHERE internalKey = ' . $modx->documentObject['createdby']);

          Is it what you want or i am wrong?
            God loves me. 【ツ】


            MODX.ir (Persian Support)

            Boplo.ir/modx/ (Persian)
            • 25551 ☆ A M B ☆
            • 1,231 Posts
            Hey,

            I tried this in a tv and I got a parse error. I may not of done it right as I am not a coder of any sort.

            $sql = $modx->db->query( 'SELECT gametitle1 FROM modx_web_user_attributes_extended WHERE internalKey = ' . $modx->documentObject['createdby']);


            The following works as a snippet but is there a simpler way to collect that info?  I want to do it this exact thing but using a TV.  I need the table value to go in to a TV as it’s the TV that displays the information on my pages.

            <?php
            $sql = $modx->db->query( 'SELECT gametitle1 FROM modx_web_user_attributes_extended WHERE internalKey = '. $modx->documentObject['createdby']);
            
            $docInfo = $modx->getDocument($modx->documentIdentifier);
            $webuserId = str_replace('-','',$docInfo['createdby']);
            $createdon = date($timestampformat,$docInfo['createdon']);
            $tbl = $modx->getFullTableName('web_user_attributes_extended');
            $query = "SELECT gametitle1 FROM $tbl WHERE internalKey = $webuserId"; 
            $rs = $modx->dbQuery($query);
            $limit = $modx->recordCount($rs); 
            if($limit==1) {
              $resourceauthor = $modx->fetchRow($rs); 
              $webUserName = $resourceauthor['gametitle1'];  
            return $webUserName;
            }
            return;
            ?>


              Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
              AugmentBLU - MODX Partner

              BLUcart - MODX Revolution E-Commerce & Shopping Cart
              • 4041
              • 788 Posts
              Try this:

              <?php
              $output ='';
              $sql = $modx->db->query( 'SELECT gametitle1 FROM modx_web_user_attributes_extended WHERE internalKey = '. $modx->documentObject['createdby']);
              
              $docInfo = $modx->getDocument($modx->documentIdentifier);
              $webuserId = str_replace('-','',$docInfo['createdby']);
              $createdon = date($timestampformat,$docInfo['createdon']);
              $tbl = $modx->getFullTableName('web_user_attributes_extended');
              $query = "SELECT gametitle1 FROM $tbl WHERE internalKey = $webuserId"; 
              $rs = $modx->dbQuery($query);
              $limit = $modx->recordCount($rs); 
                if($limit==1) {
                  $resourceauthor = $modx->fetchRow($rs); 
                  $output .=$resourceauthor['gametitle1']; 
                 }
              return $output;
              ?>


              Only change was to create the $output and add to it, then return the result. Hope it helps smiley
                xforum
                http://frsbuilders.net (under construction) forum for evolution
                • 25551 ☆ A M B ☆
                • 1,231 Posts
                Yeah that works as a snippet on a page but again, how do I get the same function to work in a TV on a given page?  I have pages that are created by users and I want to display that persons info by taking the TV variable and putting it in to Phx.  Everything works as it should but I need the TV value to be relevant to the user. 

                This works how it should in a TV... but it’s only taking the information for user 97 where I would like that to be either the ID or internalKey the user who created it, or even cretedby.  That would then allow me to use the TV on any page rather than just display results for user 97.  The way I have it working requires the info to be taken for a TV value so I need to show how get the code below to work but replace the 97 with [*createdby*].

                @SELECT gametitle3 FROM modx_web_user_attributes_extended WHERE internalKey = 97;


                I understand that the @SELECT is a database query so would @EVAL be more what I need to look at?
                  Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
                  AugmentBLU - MODX Partner

                  BLUcart - MODX Revolution E-Commerce & Shopping Cart
                  • 30223
                  • 1,010 Posts
                  I’m not quite sure why you’d want to use a TV for that. Why don;t you simply replace the TV in the PHx call with the snippet? Sure you can call the snippet from within the TV with @EVAL but that seems to me to be complicating things too much. It’s totally unnecessary.

                    • 4172
                    • 5,888 Posts
                    you can run a snippet and return its output by using the @EVAL - binding:
                    @EVAL return $modx->runSnippet('yoursnippet');
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!