...

View Full Version : Variables not place into string from included file..



Mhtml
04-08-2003, 03:57 PM
I've included a file into my page:

require ("template.php");

Now in template.php I have:

strEmoticons = "<div class=\"emoticons\">$em1,$em2,$em3</div>";

Now in my mysql query loopy thingy:

while ($i<$numRows){
$em1 = mysql_result($result,$i,"em01");
$em2 = mysql_result($result,$i,"em02");
$em3 = mysql_result($result,$i,"em03");
echo strEmoticons;
i++}

The values for $em1, 2 and 3 aren't placed into the string.
I can fix it by have {em1}{em2}{em3} and replacing them in the string using str_replace or by including the file each time I loop, but I'd rather have it working like it would if I didn't just include it.
TIA! :):D:confused:

ASAAKI
04-08-2003, 05:04 PM
maybe it's because you forgot the "$" infront of the variable names strEmoticons, and the last "i" in the loop.


PHP:--------------------------------------------------------------------------------
while ($i<$numRows){
$em1 = mysql_result($result,$i,"em01");
$em2 = mysql_result($result,$i,"em02");
$em3 = mysql_result($result,$i,"em03");
echo $strEmoticons;
$i++}


___________
edit

just noticed, u forgot the dollar sign before "strEmoticons" in your template file as well.

Mhtml
04-08-2003, 10:43 PM
My real code had them, the above is changed to make it easier to see what I'm doing.

It will work if I have the include in the loop after I set what em1 em2 em3 are though.

pardicity3
04-09-2003, 02:26 AM
Your recquire isn't inside of a seperate function or anything like that, thus making the variables only in the scope of the function? That is the first thing I would look for.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum