Jump to content

[SOLVED] Mysql string with variables problem


Smicks

Recommended Posts

Ok, I'm having a little trouble and have found nothing to help me with it so far... I'm not sure the easiest was to explain it, but here it goes: I have html stored in my database, which contains php arrays throughout the html, such as {$variable[0]}. When I output the text, it everything else is fine, except it doesn't replace the text "{$variable[0]}" with the value of $variable[0]. It just outputs the variable name between the brackets.

 

When I tried to do it WITHOUT calling it from the database by just making $variable[0] be the string itself, and output it, it worked fine, like:

 

<?php
$variable = array("value1", "value2", "value3");
echo "The first value is {$variable['0]}.";
?>

 

And that would output "The first value is value1.", which is what I wanted. What I basically want to know is what's different from the string of text in the php there, and the string of text in the mysql result that makes it mess up?

Ok, well my table is laid out like this:

 

id | html
1 | some html {$variable[0]} and some more html
2 | more html {$variable[0]} and even more html

 

and the query I'm using (i'm already logged in and have the right DB selected) is:

 

<?php
$variable = array("value1", "value2", "value3");

$get_html = sprintf("SELECT html FROM html_templates WHERE id='1'");
$get_html_query = mysql_query($get_html);
$the_result = mysql_fetch_assoc($get_html_query);

echo $the_result;
?>

 

That'll output the EXACT string from the database, with the array: "some html {$variable[0]} and some more html" While it SHOULD say "some html value1 and some more html"

 

Please tell me if I need to be more descriptive.

No, not any code, really, just the array variable between the two braces. I want the variable and braces themselves to be replaced with the value of the variable, just like it would be if it were in a normal string of text, like I said in my first post. I'm trying to figure out why that won't happen when i output the string from the database. Even if the variable wasn't defined, which it is, it would just leave an empty value instead of outputting {$variable} like it is. I'm not sure if it needs special formatting or something, so that's why I posted  :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.