We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8416
    • 173 Posts
    Hi,
    I’m using the @SELECT binding in a TV with a datagrid widget. How can I pass an argument (value) to the sql query?
    I’d like to do something like @SELECT * FROM table WHERE field_id="%value%"
    Thank you
      • 21191
      • 236 Posts
      I could be wrong, but I think you can bring in another TV or perhaps PHx might be an option.
        ~Shawn Himmelberger
        Check out my MODx Development and MODx Design Company - Himmelberger Design
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        You can use placeholders; in fact the [+DATABASE+] and [+PREFIX+] placeholders are already set for you:
        @SELECT *  FROM [+PREFIX+]tablename ...

        so you could use a snippet to set the value you want as a placeholder.

        You cannot use chunks or TVs, although you can use a TV to set a placeholder:
        @EVAL $modx->setPlaceholder('placeholdername', 'value');

        Just make sure your snippet or TV is called before your @SELECT TV so the placeholder is available.

        You could also use a plugin, but then things start getting complicated.
          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
          • 8425
          • 159 Posts
          Perfect thanks for the quick reply...
            • 8425
            • 159 Posts
            Actually it doesn’t work :-(
            I did set the placeholder "school" before invoking the TV which has the @select statement defined in the default value:
            @SELECT toursName, seats, fromDate, toDate FROM tnt_tours WHERE school="[+school+]"


            Do you know why?

            Thanks
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Is the tnt_tours table in the MODx database? If not, you’ll need to specify the database. How did you set the placeholder?
                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
                • 8425
                • 159 Posts
                Yes, the table is there and if I replace [+school+] with a value, the @select works fine.
                This is how I set the placeholder (in a snippet called before the TV):
                $modx->setPlaceholder('school', $schoolArray['school']);

                That’s strange...
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  Indeed. I’ve just finished researching and testing the @SELECT binding for my book; I’ve never actually used it. I’ll have to do some further testing and see what I get if I try the same type of query structure.
                    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
                    • 22303 MODX Staff
                    • 10,725 Posts
                    Quote from: sottwell at Jun 02, 2009, 08:48 AM

                    Indeed. I’ve just finished researching and testing the @SELECT binding for my book; I’ve never actually used it. I’ll have to do some further testing and see what I get if I try the same type of query structure.
                    It only supports the two placeholders Susan mentioned at first; it does not parse any others before executing the statement. Personally, I would use @EVAL with the DBAPI.
                      • 8425
                      • 159 Posts
                      Ok thanks OpenGeek, that explains it. I’ll use the DBAPI then...