|
Posted by Erwin Moller on 11/19/31 11:47
Heike Behrens wrote:
> Hello all!
>
> The following example
> $welt="World";
> echo "<br>Hello $welt";
> gives me "Hello World" as result. No problem so far. But why doesn't a
> string from a MySQL table behave the same? Fieldname contains the string
> "$jahr". And the output is "$jahr", and not 2006.
>
> Maybe someone has a hint? Putting $jahr in brackets or using other
> string functions on it had no effect so far. Thanks for any help!
>
> Heike
Hi Heike,
You are doing something completely different in your following code.
It has nothing to do with variable substitution.
>
>
> $db = mysql_connect($db_host,$db_user,$db_pass);
> mysql_select_db ($db_name) or die ("Cannot connect to database");
> $erg=mysql_query("select fieldname from tablename where id=20") or
> die("Error");
This query returns something we can only guess about.
fieldname now contains some value, eg 'cityname', allright?
or even jahr.
My guess is you ment 'jahr' in this case...
>
> $jahr=2006;
This just sets some variable named $jahr.
>
> if ($all=mysql_fetch_array($erg)) {
> extract($all);
You are using extract, but did you read the API at www.php.net?
Always first go to www.php.net before asking here. :-)
Read here:
http://nl3.php.net/manual/en/function.extract.php
(or the german one.)
If you read that you will find the following 'extract-type' usefull:
EXTR_OVERWRITE
> echo $fieldname;
> }
I hope that helps you out.
Good luck.
Regards,
Erwin Moller (but my german sucks.)
[Back to original message]
|