We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20889
    • 19 Posts
    Hi,
    I want to make a sql query using the value set on a placeholder. The problem is that the query does not work when I build it using the placeholder, it works if I put the value manually. Here is how I build the query usinig the placeholder and building it manually:

    $sql="select name, description from sales where id=’" . ’[+id_mod+]’ . "’";
    $sql2="select name, description from sales where id=’2’";

    The placeholder’s value is 2.

    I make the query and get the values the next way:

    $result=$modx->db->query($sql);
    $data=mysql_fetch_array($result);

    when I do a var_dump($data) using the $sql2 I get the data and when I do it using $sql I get a bool(false)

    To compare them and try to find what is happening I did a var_dump of them and what I notice is that when I build it using the placeholder it has more characters although the value is the same:

    var_dump($sql); string(71) "select name, description from sales where id=’2’"
    var_dump($sql2); string(62) "select name, description from sales where id=’2’"

    Does anybody know how to solve it huh?
    Thanks in advance
      • 33372
      • 1,611 Posts
      Placeholders are replaced with their values when the document’s content is parsed, so you can’t use them that way in a snippet. You can use the getPlaceholder function in your snippet to get its value and use it there. There may be other ways of doing what you are trying to do also (where are you setting this placeholder?).
        "Things are not what they appear to be; nor are they otherwise." - Buddha

        "Well, gee, Buddha - that wasn't very helpful..." - ZAP

        Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
        • 20889
        • 19 Posts
        lots of thanks,
        I’m setting the placeholder on other snippet. I have a form that collects information, inserts the data into a database and sets the placeholder that contains a register id to be modified, after that I have a $modx->sendforward() to the modification page that gets the id as the placeholder and make the query to get the data to be modified.
        Another way of doing it could be to call the modification page passing the id as a querystring but I don’t know how to do it if it is not a link. If I had a function that redirects to another page and could pass some data would be great. That’s why I use the placeholder to pass information from one page to another.
          • 33372
          • 1,611 Posts
          Another way to save values for later use is to store them in a $_SESSION variable (which is particularly useful if you’ll need the value on another page rather than right away in the same request).
            "Things are not what they appear to be; nor are they otherwise." - Buddha

            "Well, gee, Buddha - that wasn't very helpful..." - ZAP

            Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
            • 20889
            • 19 Posts
            Thank you,
            I’ll have a look how to use this $Session var.
              • 26435
              • 1,193 Posts
              Quote from: naish at Aug 17, 2007, 01:15 PM

              Thank you,
              I’ll have a look how to use this $Session var.
              http://php.net/session

              -sD-
              Dr. Scotty Delicious, Scientist DFPA.
                Husband, Father, Brother, Son, Programmer, Atheist, Nurse, Friend, Lover, Fighter.
                All of the above... in no specific order.


                I send pointless little messages