We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16886
    • 40 Posts
    Hi everybody, I’m a newbie in modx and i like the easy use of it, but:

    I have a problem to read the selfgenerated URL to use is in my SQL

    First I created a TV with a DATAGRID
    @SELECT 
    CONCAT("<a href='./index.php?id=45&player_id=",t1.player_id,"' title='Detail'>",t1.prename, " ", t1.name,"</a>") as NAME from...
    

    This is what i did:
    1. Format the column as link ( the link is very well created and refers to my Page with the ID=45 and the player_id of the selected row )
    2. I created a SQL via TV which need the PLAYER_ID as WHERE-Parameter and put this TV to my Content-Area on Page with the ID 45


    Before i use ModX i coded:
    $player_id=$_GET["player_id"]; 
    

    and passes the $player_id to my SQL:
    ...WHERE player_id = $player_id;
    


    How can i do this in Modx?
    How can i read the given parameter?
    How can i pass the parameter to my SQL Statement?

    I read a lot of Documentation and try many different ways to solve my problem, but nothing worked.
    It must be simple but i don’t know how...

    Thank you for every hint, tipp,...

      I love ModX!
      • 32241
      • 1,495 Posts
      I’m not sure what you’re trying to do, but you can use @EVAL, instead of @SELECT as your TV value. Basically with EVAL, you can run any php code inside TV.

      FYI, passing $_GET variable directly to the SQL statement will expose your script to serious security issue that most tech people called SQL injection. Try to filter it first using your own logic to make sure that you got the right data, or you can usse some built in function on PHP.
        Wendy Novianto
        [font=Verdana]PT DJAMOER Technology Media
        [font=Verdana]Xituz Media
        • 16886
        • 40 Posts
        Quote from: Djamoer at Mar 23, 2006, 01:25 AM

        I’m not sure what you’re trying to do, but you can use @EVAL, instead of @SELECT as your TV value...
        Hello Wendy,
        thanks for your fast reply.

        I will describe what i want to do ( sorry for my poor English ):
        I have a database containing lots of bowling scores from a German bowling association,
        before Modx i used own ( bad coded ) php-scripts to format result tables and give the user the ability to ’drill-down’ to more detailed scores

        For example:
        In the first grid i show all players and their cumulated scores,
        if i click then on a player name i used the given player_id in the URL to execute another sql and show another grid with more detailed information ( where the score was played, what kind of playing, which final place ,... )
        in the more detailed grid again i build links via sql to show the single games score for the selected player and the selected event...
        and that is what i want to realize with Modx

        Can i use @EVAL to GET the player_id from the URL?
        Can i nest @-Functions?

        If i understand correctly, is this the solution that i have to use in my TV?
        @EVAL $player_id=$_GET["player_id"]; 
        @SELECT 
        CONCAT("<a href='./index.php?id=45&player_id=",t1.player_id,"' title='Detail'>",t1.prename, " ", t1.name,"</a>") as NAME from myTab
        where player_id = $player_id
        


        thanks for reading
        LeftHanded
          I love ModX!
          • 32241
          • 1,495 Posts
          I don’t think you can combine binding (@) on TV.
          When you use EVAL, you can do mysql_query and etc just like a plain PHP script. You can use our MODx DB API, for more info about it, you can access it on http://modxcms.com/dbapi.html

          To help what you’re trying to achieve, I can suggest you a few solution:
          1. Just use your old code and run it inside MODx as a snippet. So what you need to do is create a new snippet and put that snippet on the right page where you want to display the bowling scrores table.
          2. You can use TV to fetch the data from database and use the data grid wdiget to display the score by you. I’m not sure on how to use it, because I never use DataGrid widget before combine with TV. I hope someone in this forum will be able to help you with this.

            Wendy Novianto
            [font=Verdana]PT DJAMOER Technology Media
            [font=Verdana]Xituz Media
          • You can even use your original php file, just include() it in a snippet, and return any values instead of having them display themselves.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 16886
              • 40 Posts
              Hello and thanks again for the answers...

              One of my reasons to use Modx was:
              That i don’t have to use my php-files anymore, all in one application only using the standard functions of Modx.
              But ok, if this is not working i have to do coding myself...

              If i understand correctly, is this a part of the way to success:

              1. Create a SNIPPET with the php-code somehing like that:

              <?php
              // SNIPPET: GET_THE_PLAYER_SCORES
              $player_id=$_GET["player_id"]; 
              $table = $modx->getFullTableName("myScores");
              $messages = $modx->db->select("player_id,name,prename,sum(pins)", $table, "player_id = $player_id", "name DESC", "10");
              


              2. Create a TV with following settings:
              [b]// This is the point i don't understand !!![/b]
              In the default value field: [[GET_THE_PLAYER_SCORES]]
              Using the Datagrid Widget: i dont't have a fieldlist or something like that???
              


              3. Put the generated TV in the Document

              I think Modx is more powerful...
              Is there a more detailed documentation of the datagrid-widget available?
              Any examples?

              I wondering every day, what special functions all the cracks building to work with Modx.
              Great work! But can someone check this needed function to work with Modx standards?

              Thank you
              LeftHanded
                I love ModX!
                • 14721
                • 16 Posts
                I think you can combine your EVAL / SELECT statements something like this... (it’s a little tricky because of the nested quotes, but hopefully you get the idea):

                @EVAL $player_id=$_GET["player_id"]; return $modx->db->query(
                "SELECT CONCAT(\"<a href='./index.php?id=45&player_id=\",t1.player_id,\"' title='Detail'>\",t1.prename, \" \", t1.name,\"</a>\") as NAME from myTab where player_id = $player_id\");
                


                It would be cooler, of course, if @SELECT did tag replacement so you could just stick {$_GET["player_id"]} (OR chunks or other TV’s) right into your SQL. Maybe someone will make an @SUPERSELECT that works that way someday smiley

                -- Jorge.
                • FYI, you can already put the {$_GET[’player_id’]} in PHP strings, so just do something like this:

                  @EVAL return $modx->db->query("SELECT CONCAT('<a href=\"[~45~]&player_id=', t1.player_id, '\"', ' title=\"Detail\">', t1.prename, ' ', t1.name, '</a>') as NAME from myTab where player_id = {$_GET['player_id']}");
                    • 31337
                    • 258 Posts
                    Quote from: OpenGeek at Apr 11, 2006, 10:12 PM

                    FYI, you can already put the {$_GET[’player_id’]} in PHP strings, so just do something like this:

                    @EVAL return $modx->db->query("SELECT CONCAT('<a href=\"[~45~]&player_id=', t1.player_id, '\"', ' title=\"Detail\">', t1.prename, ' ', t1.name, '</a>') as NAME from myTab where player_id = {$_GET['player_id']}");


                    DON’T do that verbatim. Assign $_GET[’player_id’] to a variable first, filter it to make sure you’re not getting SQL injection code in there, and then run the query above using the variable instead of accessing $_GET directly.
                      • 16886
                      • 40 Posts
                      Thanks a lot!
                      Will try ( the secure one ) and report to the community
                      Nice ideas opened my understanding level, thanks again
                        I love ModX!