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
    I need some help to make the default value of a TV be drawn direct from the database.

    mysnippet is

    <?php
    $docInfo = $modx->getDocument($modx->documentIdentifier);
    $webuserId = str_replace('-','',$docInfo['createdby']);
    $createdon = date($timestampformat,$docInfo['createdon']);
    $tbl = $modx->getFullTableName('web_user_attributes');
    $query = "SELECT userid FROM $tbl WHERE id = $webuserId"; 
    $rs = $modx->dbQuery($query);
    $limit = $modx->recordCount($rs); 
    if($limit==1) {
      $resourceauthor = $modx->fetchRow($rs); 
      $webUserName = $resourceauthor['userid'];  
    return $webUserName;
    }
    return;
    ?>


    My TV is

    @EVAL return $modx->runSnippet('userID');


    The snippet runs fine if put in the content of a document... it displays what I wish but I need this displayed in the value of a TV. What I use the @EVAL code it errors.

    Warning: Cannot modify header information - headers already sent by (output started at /home/xhtmlde/public_html/manager/includes/header.inc.php:5) in /home/xxx/public_html/manager/includes/document.parser.class.inc.php on line 2620
    « MODx Parse Error »
    MODx encountered the following error while attempting to parse the requested resource:
    « Execution of a query to the database failed - 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 ’’ at line 1 »
    SQL: SELECT userid FROM `xxx_site`.`modx_web_user_attributes` WHERE id =

    I need to somehow set the id to the current document ID that the TV is being viewed at to make it work... If I hardcode WHERE id = 40 for example, it pulls the piece of info I need off the database. Is there a way to set the id from the current id? I tried several ideas using $id = $modx->documentIdentifier; and then putting WHERE id = $id and some other variations to try to get it working but only the hardcoded way seemed to work... I need the id to display the current document id to do what I need to.

    Any help would be great!
      Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
      AugmentBLU - MODX Partner

      BLUcart - MODX Revolution E-Commerce & Shopping Cart
      • 3749
      • 24,544 Posts
      Could you use getLoginUserID() instead of the query?
        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
        Thanks Bob, that worked for the snippet in a document but again causes the  TV to error. 

        UserImage
        UserImage
        Warning: Cannot modify header information - headers already sent by (output started at /home/xxx/public_html/manager/includes/header.inc.php:5) in /home/xxx/public_html/manager/includes/document.parser.class.inc.php on line 2620
        « MODx Parse Error »
        MODx encountered the following error while attempting to parse the requested resource:
        « Execution of a query to the database failed - 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 ’’ at line 1 »
              SQL: SELECT photo FROM `xxx_site`.`modx_web_user_attributes` WHERE id = ()
              [Copy SQL to ClipBoard]

        Parser timing
          MySQL: 0.0100 s (3 Requests)
          PHP: 1239441686.4859 s
          Total: 1239441686.4959 s


        Basically I’m trying to find the document creators userID, then query the database for a specific table and it’s content and then place that info into a TV as plain text.

        So on the document I want the TV to show /assets/images/myimage.jpg for example. The /assets/images/myimage.jpg is stored in a table in modx and I wish to find that info based on the document creator userID. On each of the documents where the TV is available I want it to reflect the creators table info...

        document (100) userID (40) createdby (40) TV(/assets/images/user40.jpg)

        document (101) userID (42) createdby (42) TV(/assets/images/user42.jpg)

        document (112) userID (30) createdby (30) TV(/assets/images/user30.jpg)

        I tried this @SELECT in a TV but only works when you hardcode the ID... I need it to pick up the created by ID without hardcoding. How can I make the 40 be replaced with the document creators ID
        @SELECT email FROM [+PREFIX+]web_user_attributes WHERE id = (40)
          Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
          AugmentBLU - MODX Partner

          BLUcart - MODX Revolution E-Commerce & Shopping Cart
          • 25551 ☆ A M B ☆
          • 1,231 Posts
          Anyone able to help out with this at all?
            Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
            AugmentBLU - MODX Partner

            BLUcart - MODX Revolution E-Commerce & Shopping Cart
            • 25551 ☆ A M B ☆
            • 1,231 Posts
            Quote from: ganeshXL at Apr 12, 2009, 09:51 AM

            It’s Easter holidays, do you expect everyone to sit at home behind their computers? huh

            Not everyone follows religious holidays... grin

            Thanks for the snippet idea, it is not what I am looking for exactly. It is working as it should in the document content or if I put it in the TV and use [*myTV*] in the document but this is not what I am asking. I need the TV to display the actual TV output. So if [*myTV*] outputs "assets/image/user-40.jpg" I need that actual information in the TV rather than [[userimage]]. I want to use a tagging system that takes the document creators information so that Ditto or a custom search function can search through TVs and then categorise each document based on the TV value. I can’t do that if the TV value is [[userimage]] as I need it to be "assets/image/user-40.jpg" for example. Is it not possible to populate a TV value directly from a chosen database table and ID? I used the @SELECT function with a delimited list and it does show what I want but it’s taking all the values in the table as I can’t get the ID to be relative to a page. It errors when ever I try to make the ID dynamic, only hardcoding works.

            An example - @SELECT email FROM [+PREFIX+]web_user_attributes WHERE id = (40) works but it’s going to output the same code for every page that uses that TV when I want it to output the id of the relative document creator.

            I was hoping to be able to do this...
            Document 148 - createdby 40 - TV value @SELECT userimage FROM [+PREFIX+]web_user_attributes WHERE id = (40)
            Document 149 - createdby 41 - TV value @SELECT userimage FROM [+PREFIX+]web_user_attributes WHERE id = (41)
            Document 150 - createdby 42 - TV value @SELECT userimage FROM [+PREFIX+]web_user_attributes WHERE id = (42)

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

              BLUcart - MODX Revolution E-Commerce & Shopping Cart