Jump to content


Photo

variables inside of variables


  • Please log in to reply
6 replies to this topic

#1 rempires

rempires
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts
  • LocationIndiana (USA)

Posted 29 October 2006 - 07:06 AM

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

$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

the variable $HeaderFormat in this case contains

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

function showdata()
{
global $PostDateTime, $HeaderFormat;
echo "$HeaderFormat";
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







#2 bqallover

bqallover
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts
  • LocationLeeds, UK

Posted 29 October 2006 - 07:40 AM

You might want to take a look at this thread: http://www.phpfreaks...c,112882.0.html

#3 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 29 October 2006 - 07:45 AM

eval()
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#4 rempires

rempires
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts
  • LocationIndiana (USA)

Posted 29 October 2006 - 07:52 AM

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

#5 rempires

rempires
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts
  • LocationIndiana (USA)

Posted 29 October 2006 - 07:52 AM


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

#6 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 29 October 2006 - 08:05 AM

read the part in the manual about mixing html with php code
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#7 rempires

rempires
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts
  • LocationIndiana (USA)

Posted 29 October 2006 - 08:08 AM

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

eval("\$HeaderFormat = \"$HeaderFormat\";");


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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users