Jump to content

Using Php Variables Stored in Mysql Entries


weldonj

Recommended Posts

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.
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...

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 $test

If 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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.