PHP Variables
I've got a MySQL table, and I would like to put variables into the table..
IE row Name has this data: "Hello $firstname"
Each page that calls this data has $firstname defined and when you call in the row Name, it puts in the data that was put in $firstname
Example:
row Name is "Hello $firstname";
<?php
$firstname = \"Joe\";
echo $row[name]
?>
It should say "Hello Joe"
Can this be done?
I tried it that way and it didn't work.
arin posted this at 22:40 — 25th May 2002.
They have: 8 posts
Joined: May 2002
The PHP command eval should do what you're looking for. From the PHP Manual:
<?php
$string = 'cup';
$name = 'coffee';
$str = 'This is a $string with my $name in it.<br>';
echo $str;
eval (\"\$str = \\"$str\\";\");
echo $str;
?>
The above example will show
This is a $string with my $name in it.
This is a cup with my coffee in it.
If that doesn't work, then you might want to investigate the sprintf command, which is more "friendly" for C/C++ programmers...
Hope this helps!
arin
Web hosting from just $2 a month! http://www.xeosdd.net
nike_guy_man posted this at 22:52 — 25th May 2002.
They have: 840 posts
Joined: Sep 2000
Thank you very much!
Works like a charm, for now
If it doesn't work, I'll check out the PHP manual for eval and sprintf
Thanks a billion
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.