Re: Putting variables in a string
| From: | Papp Gyozo | Date: | Tue, 28 Aug 2001 22:46:47 +0000 |
| Subject: | Re: Putting variables in a string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-64916@lists.php.net to get a copy of this message | ||
Hi,
try to change the line in that loop to this one:
$sql .= $key.' = '.$$key.', ';
----- Original Message -----
From: P.Agenbag <internet@psimation.com>
To: <php-general@lists.php.net>
Sent: Tuesday, August 28, 2001 7:54 PM
Subject: [PHP] Putting variables in a string
> I am trying to make a string that will contain variables.
>
> The resulting string will be a sql query string and must look something
> like
>
> " update $table_name set key='$key' , next='$next' where id =
> $id"
>
> Since the variable name is the same as the key name, I tried to generate
> this string with a foreach statement looking something like this:
>
> foreach( $myrow as $key=>$val) {
> $sql .= "$key = ' \$$key ' ,";
> }
>
> This then makes the string look as follow:
>
> key='$key',next='$next', and I just add the rest of the string to the
> front and back, yet, when I now try to use this string in the
> mysql_query() function, it does not recognise the '$key' and '$next' as
> variables and add them into the db as $key and $next. I need to know how
> I am going to make this string "recognise" the variables in them.
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>