SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Not Bad, eh? Justin Sampson's Avatar
    Join Date
    Aug 2000
    Location
    N.S., Canada
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's me again

    I have a file called header.php that looks like this

    PHP Code:
    <?
    function pheader()
    {
    echo 
    "the article id is $id"; }
    ?>
    and a file called article.php

    PHP Code:
    <?
    include("header.php");

    pheader(); ?>
    When I go to article.php?id=1 the id doesn't end up on the page? Is it sopposed to do that? or am I doing something wrong?

    Thanks,
    Justin Sampson

  2. #2
    SitePoint Member
    Join Date
    Feb 2001
    Location
    Iowa
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to pass the article for it to be available to pheader(), so the function would actually look like this:
    pheader( $id )
    {

    echo( "The article id is: $id." );

    }

    and called by:

    pheader( $id );

    HTH
    Justin

  3. #3
    SitePoint Member
    Join Date
    Feb 2001
    Location
    Utah
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd make $id global inside of pheader() ...

    <?

    function pheader()
    {
    global $id;
    echo "the article id is $id";
    }

    ?>

    That's cleaner and easier to follow..

    SeanM

  4. #4
    SitePoint Evangelist
    Join Date
    May 2000
    Location
    Canada
    Posts
    533
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sean, Global Variables arent the best thing when programming.. sure, they're good in this case, but in general, global variables are an unnecessary evil .. ( you get into issues when you are doing REAL programming, php is not real programming )
    cogito, ergo sum


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
  •