We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19114
    • 0 Posts
    Hi. I am new to PHP and sql query.

    Is it possible to use placeholders in snippets? Or is there any way I could get the "longtitle" of the document (where I call the snippet) into the place where I define "WHERE" in a query?

    I’m making personalized document for each web user and I’d call all the data from the db where the exact web user is mentioned. Possibility to use "longtitles" would save time, otherwise I was planned to make own snippet for every user.


    From this:
    $sql = $modx->db->query( ’SELECT * FROM `tblprojects` where name="Tim"’);

    Into something like this:
    $sql = $modx->db->query( ’SELECT * FROM `tblprojects` where name="[*longtitle*]"’);


    Thanks.
      • 10487 MODX Staff
      • 1,535 Posts
      You can’t use the MODx tag syntax in PHP code like that (well, not for stuff like that anyway). To get access to one of the page’s variables, such as the longtitle, use the documentObject array:
      $modx->documentObject['longtitle']

      So, in your example, it would be:
      $sql = $modx->db->query( 'SELECT * FROM `tblprojects` where name="' . $modx->documentObject['longtitle'] . '"');
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 19114
        • 0 Posts
        Thanks! I have been struggling with this way too long. smiley