We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20080
    • 17 Posts
    I’m trying to display a custom table that shows the logged in user’s stats.
    I have a snippet called [!me!] which has this content:
    <?php
    $user = $modx->getLoginUserName();
    $modx->setPlaceholder('user',$user);
    ?>

    I have a TV called [*my_stats*] (using Datagrid Widget)
    @SELECT field1,field2,field3,field4 FROM custom_table WHERE user ='[+user+]'


    It seems like the data inside of the [+user+] placeholder is not getting passed to the TV. I am calling the [!me!] snippet in the header of the template and displaying the [+user+] placeholder perfectly fine in the content area (above the area I am displaying the data grid TV).

    I edited the TV and manually added the username and the data pulls up fine, but when I use the place holder, I get an "empty result."

    Is there something I’m missing here? Are there various or strict rules on passing a placeholder into a TV? Does it depend on placement of the Snippet Call or output of the TV?
      www.DMSalesSolutions.com New Site using Modx (still learning though)
      • 2611
      • 394 Posts
      If i’m correct everything gets parsed in order...so you would have to call the snippet BEFORE you call
      @SELECT
        Follow me on twitter: @b03tz
        Follow SCHERP Ontwikkeling on twitter: @scherpontwikkel
        CodeMaster
        • 20080
        • 17 Posts
        Thanks for the reply. That’s what I thought. So I called my Snippet in the template header and the TV is in the body. But no go. The placeholder works in the content, but doesn;t seem to get passed to the TV.
          www.DMSalesSolutions.com New Site using Modx (still learning though)
          • 4172
          • 5,888 Posts
          perhaps you can try this:

          @EVAL return $modx->db->select('field1,field2,field3,field4','custom_table','user='.$modx->getPlaceholder('user'));


          or:
          @EVAL return $modx->db->select('field1,field2,field3,field4','custom_table','user='.$modx->getLoginUserName());

            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 20080
            • 17 Posts
            Thanks again for responding.

            Unfortunaly it didn’t work, but I get different errors now which help. This is what I used.
            @EVAL return $modx->db->select('field1,field2,field3,field4','custom_table','user='.$modx->getLoginUserName());


            The problem is that I get a SQL error. It says that there is No Column called "value" of "$modx->getLoginUserName()" So in the example I’m logged in as "moises". The error says there is no column called "moises" So I know the code is working. Not sure why its adding the value of the whrere field and thinking its a column.

            MODx encountered the following error while attempting to parse the requested resource:
            « Execution of a query to the database failed - Unknown column ’moises’ in ’where clause’ »

            When I use this it works fine:
            @EVAL return $modx->db->select('field1,field2,field3,field4','custom_table','user="moises"');


            I tried several combinations, but can;t get it to work. Either returns the error above or no results.

            Any thoughts? I love the fact that there are many ways to get the same results with modx.
              www.DMSalesSolutions.com New Site using Modx (still learning though)
              • 20080
              • 17 Posts
              HOUSTON... NO More Problem!!!
              It finally worked using this.
              @EVAL return $modx->db->select('field1,field2,field3,field4','custom_table','user="'.$modx->getLoginUserName().'"');


              Had to add the double quotes and single quote into the sql query... ’ user= " ’ .$modx->getLoginUserName(). ’ " ’

              Thank you so much for helping me get there!

              Now each user can see a small table with their results when they navigate to that page!
                www.DMSalesSolutions.com New Site using Modx (still learning though)