Jump to content

Archived

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

rempires

variables inside of variables

Recommended Posts

Okay, i guess to start, i have a page and i'm trying to echo a variable that containes a some html and other variables, this data is stored in a database, so it starts like this

[code]$sql = "SELECT HeaderFormat FROM News_Format WHERE FormatID='$format'";
$result = mysql_query($sql)
or die("Failed to run query to get format data.");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$HeaderFormat = $row['HeaderFormat'];
unset($result); //must be done for later in script[/code]

the variable $HeaderFormat in this case contains

[code]<table border='1' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='100%' id='AutoNumber1'>
  <tr>
    <td width='33%'>$postDate</td>
    <td width='33%'>$title</td>
    <td width='34%'>$user </td>
  </tr>
  <tr>
    <td width='100%' colspan='3'>
    <font color='#ffffff'> $header ...</font>
    <p align='center'>
    $views | $comments | $fullstory
    </td>
  </tr>
</table>[/code] - that was copied directly from the database

the next 100 or so lines jsut determines what the otehr variables like $views, $comments are.

we then call a function, this is the next time heaerFormat is tuched, all it is is

[code]function showdata()
{
global $PostDateTime, $HeaderFormat;
echo "$HeaderFormat";
[/code]
well tehre is a little more code, but nothing touches that variable, when this script is displayed, teh html takes affect but the browser will output:

$postDate $title $user
$header ...

$views | $comments | $fullstory

the variables still show up, i want the variables to show the data they obtained earlier, i can't figure this one out because if i take that exact same code from the database and put it into $header bypasses the whole database process it works perfect, is there some way the mysql dataabase works that interferring with this, please help

thanks in advance, john

p.s. if you need more code please ask the entire script is 115 lines, not to many but i didn't want to post all that if it's not necisary





Share this post


Link to post
Share on other sites
You might want to take a look at this thread: [url=http://www.phpfreaks.com/forums/index.php/topic,112882.0.html]http://www.phpfreaks.com/forums/index.php/topic,112882.0.html[/url]

Share this post


Link to post
Share on other sites
I had tried that, eval() doesn't seem to like the "<" & ">" that are stored in the database...

Share this post


Link to post
Share on other sites

Parse error: syntax error, unexpected '<' in /home/revoicc1/public_html/includes/reNews/ProcessNews.php(108) : eval()'d code on line 1

Share this post


Link to post
Share on other sites
thanks for everyones help, it was the eval function, i jsut wasn't using it right, still don't get howcome it did what it did, but i guess i'll look into it more alter, it's 2am here....

btw code was

[quote]
eval("\$HeaderFormat = \"$HeaderFormat\";");[/quote]

i'll figure out why tommorrow, thanks again for all the help

Share this post


Link to post
Share on other sites

×

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.