weldonj Posted August 24, 2006 Share Posted August 24, 2006 I'm trying to figure out how to store php variables within mysql fields and then call these nested php variables.Say I have mysql field "descriptio"n which is a bunch of text:description="mostly text but i sometimes want a php variable called $id and get its value"but then when I try and echo this row in php:echo $description; my output will be "mostly text but i sometimes want a php variable called $id and get its value"I tried different things within mysql and the field description:description="mostly text but i sometimes want a php variable called <?php echo $id;?> and get its value"but then myoutput is just: "mostly text but i sometimes want a php variable called $id and get its value <?php echo $id;?> and get its value"; i can't believe i can't figure this out. I think eval might help me out but I've tried various combinations and had no luck. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 24, 2006 Share Posted August 24, 2006 if you have PHP in a database, PHP will treat the PHP as text. It wont parse it. In order to parse it you'll have to use eval Quote Link to comment Share on other sites More sharing options...
weldonj Posted August 24, 2006 Author Share Posted August 24, 2006 I'm not sure how to get eval to work. Not all of my database entries will have php variables in them.I do return eval($description);where description="database entry i want my $phpvariable;?> here";and i keep getting database entry i want my $phpvariable?> here";The docs on eval have been of no helps so if anyone could show me how to embed the php variable in my mysql database it would be appreciated. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 25, 2006 Share Posted August 25, 2006 You'll want to do this:[code=php:0]eval("echo \"$description\"");[/code]In order for your PHP variables to be parsed Quote Link to comment Share on other sites More sharing options...
weldonj Posted September 5, 2006 Author Share Posted September 5, 2006 Does it make a difference that description is getting called from a mysql database using myrow. Suppose in my database the field description is: This is a $testIf I pull from the database and do: $test="real name";$sql = "my select statement";$result = mysql_query($sql) or die(mysql_error());while ($myrow = mysql_fetch_array($result)) {$description=$myrow["description"]; }eval('echo $description;');My output is "this is a $test"however if I instead do this:$test="real name";//replacing the $description=myrow["$description"] below;$description="This is a $test"; eval('echo $description;');then i get the correct "this is a real name"So clearly the $description=myrow["$description"] line is screwing things up. Can anyone explain to me how to get around this? or why this is causing problems.Thanks Quote Link to comment Share on other sites More sharing options...
fenway Posted September 5, 2006 Share Posted September 5, 2006 I can't see how that would make a difference, unless somehow it's getting stick in single-quotes, even through the eval(), which makes no sense. But I'm not a PHP guy. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 5, 2006 Share Posted September 5, 2006 Whats in your eval should be in double quotes, and the $description variable should be surrounded in double quotes too.So your eval should be like this:eval("echo \"$description;\""); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.