Results 1 to 2 of 2

Thread: Resolving \$variables in a PHP string *RESOLVED*

  1. #1

    Thread Starter
    Addicted Member mralston's Avatar
    Join Date
    Aug 2002
    Location
    Altrincham Nr Manchester, England
    Posts
    141

    Resolving \$variables in a PHP string *RESOLVED*

    I'm pulling a piece of SQL code from a field in a database. The code that I'm getting back contains PHP variable place holders. For example the data I get back from the database might be something like:

    SELECT * FROM table WHERE field=$variablename

    I would then want to run this SQL, but obviously I need $variablename to be replaced with the value of the variable. At the moment it's as if the code I get back is really:

    SELECT * FROM table WHERE field=\$variablename

    So the code that I get back and run against the database doesn't get filled with the values of any $ style variables that might be in it.

    Is there a function or something that will loop through the SQL replacing any variables with their values?
    Last edited by mralston; Oct 15th, 2002 at 07:56 AM.

  2. #2

    Thread Starter
    Addicted Member mralston's Avatar
    Join Date
    Aug 2002
    Location
    Altrincham Nr Manchester, England
    Posts
    141
    eval("\$sql=\"SELECT * FROM table WHERE field=$variablename\";");

    Does the trick.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width