Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post

    Variables not place into string from included file..

    I've included a file into my page:
    PHP Code:
    require ("template.php"); 
    Now in template.php I have:
    PHP Code:
    strEmoticons "<div class=\"emoticons\">$em1,$em2,$em3</div>"
    Now in my mysql query loopy thingy:
    PHP Code:
    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!
    Last edited by Mhtml; 04-08-2003 at 04:00 PM.
    Omnis mico antequam dominus Spookster!

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    This little Earth.
    Posts
    383
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Last edited by ASAAKI; 04-08-2003 at 09:55 PM.
    'If you don't stand for something, you'll fall for anything.'

  • #3
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.
    Omnis mico antequam dominus Spookster!

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Iowa / Notre Dame
    Posts
    538
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    My Site {Mike's Adventures}

    Yikes, forums are almost too much fun.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •