Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Why is my Variable Value not carrying through?

  1. #1
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default Why is my Variable Value not carrying through?

    I have a tiny file that sets some variables...

    Code:
    <? $artist_id = 46; 
       $header = 'artist-header-nav.php';
       include_once('artist-template-n.php'); ?>
    and then runs a php script that uses the variables. For some reason the $header variable isn't recognized in the template file...

    Code:
    <div id="pageheader"><? include('$header'); ?></div>
    What am I missing? Thanks! erin

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    I think you would need to do this:
    Code:
    <div id="pageheader"><? include($header); ?></div>
    Jeremy | jfein.net

  3. #3
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    If that doesn't work, try to simply echo the variable $header to see if it is getting passed through to the script.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    @thetestingsite
    It will defently work. lol.
    Jeremy | jfein.net

  5. #5
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    @nile, I know it should work; however, there are some cases in which that just isn't the case. It is always nice to have a backup plan when troubleshooting something (especially in a case like this).
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  6. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Well yea, I guess so...
    Jeremy | jfein.net

  7. #7
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    You guys kinda lost me a bit. I tried this... is that what you meant? Anyway, it didn't work.

    Code:
    <? include('echo $header.".php";'); ?>
    Also tried this... and it didn't work.

    Code:
    <? include('echo $header;'); ?>
    Last edited by kuau; 02-04-2008 at 01:37 AM. Reason: posted by accident

  8. #8
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Actually, what I suggested was if this doesn't work:

    Code:
    <?php include($header); ?>
    then try this instead to see if the variable is getting passed:

    Code:
    <?php echo $header; ?>
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  9. #9
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Just do this:
    Code:
    <div id="pageheader"><? include($header); ?></div>
    Jeremy | jfein.net

  10. #10
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    I did try echoing the variable and it gave me the correct filename. So then I did what Nile suggested:

    Code:
    <? include($header); ?>
    and it worked!! Thanks so much.

    What I don't understand is this... if I were not using variables, I would do the command like this:

    Code:
    <? include('artist-header-nav.php'); ?>
    Replacing the variable above, it ends up being:

    Code:
    <? include(artist-header-nav.php); ?>
    So does that mean I shouldn't (or don't have to) use the single quotes normally? That seems to be what was making it not work.

    Thanks so much for helping me. erin
    Last edited by kuau; 02-04-2008 at 03:04 AM.

Bookmarks

Posting Permissions

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