Page 1 of 1

PHP Variable in MySQL db

Posted: Tue Mar 29, 2005 7:49 am
by anjanesh
I've a row from a db :
$row = mysql_fetch_assoc($res);
$row['something'] contains The number is $var

If $var is set to 5 in the php page I want
echo $row['something']; to output - The number is 5

I tried entering The number is {$var} in the db but no luck.
exec cannot be used here I guess.

I know this has been posted many times here - Just dont know what search terms to give.
Thanks

Posted: Tue Mar 29, 2005 7:57 am
by n00b Saibot
eval() may be it.

Posted: Tue Mar 29, 2005 8:29 am
by onion2k
n00b Saibot wrote:eval() may be it.
Or str_replace("\$var",$var,$row['something']); .. depends if you know what variables are going to be i the database string.

Posted: Tue Mar 29, 2005 8:51 am
by feyd
a regular expression to handle it wouldn't be too hard either... this is getting into template stuff though, which honestly, should probably not have php things in them.

Posted: Tue Mar 29, 2005 10:12 am
by anjanesh
eval() gives unexpected T_STRING
str_replace can be used for a particular case but I'll have various variables which I may not know.
I didnt realize there wasnt a method (function) for this. Guess I'll to actually code for this.
Fine. I asked this since $var in a string gets parsed so I was wondering if theres a method for string in db.
So this is the way phpBB and others parse - they have separate user defined function to parse them right ?

Posted: Tue Mar 29, 2005 11:08 am
by feyd
phpBB among others use a template engine which has it's own syntax and parsing system for templated variables in strings.