Why is there a ? in the link and what does the whole link means

Discussion in 'PHP' started by askscript, Apr 18, 2010.

  1. #1
    Hi,

    i am a beginner learner of PHP.

    i come across this link to a php script:

    <a=href="hello.php?name=Michael">Michael</a>

    I wonder what does the whole link structure means"
    hello.php is the file name.
    what is the "?" doing there?

    Anyone can advise? Thanks.
     
    askscript, Apr 18, 2010 IP
  2. Warll

    Warll Peon

    Messages:
    122
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Its called the query string.

    May the Google be with you.
     
    Warll, Apr 18, 2010 IP
  3. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #3

    The "?" indicated the query string that is being passed to the php page. The information that follows will be name=value pairs, seperated by "&".

    Inside the PHP script, you can access them through the $_GET superglobal.
     
    lukeg32, Apr 19, 2010 IP
  4. Gray Fox

    Gray Fox Well-Known Member

    Messages:
    196
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    130
    #4
    Try it out for yourself:
    index.php
    
    // index.php?somevar=somevalue&somearray[]=othervalue&and=so+on
    
    var_dump($_GET);
    
    PHP:
     
    Gray Fox, Apr 19, 2010 IP
  5. weaverIT

    weaverIT Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    hei,
    its <a href="hello.php?name=Michael">Michael</a>
    <a> id for anchor tag --- for setting hyperlink , so while clicking this it will get redirected to hello.php pahe with an argument name-Michael
    ? -- is used for appending the arguments with the page, here we are passing the name as get parameter along with the hyperlink page.
    second argument owards we will be using an & sign for appending it to the url.

    Hope this answers your question!
     
    weaverIT, Apr 19, 2010 IP
  6. askscript

    askscript Member

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #6
    yes, thank you and to all others too.

    However,
    I have always wonder what is the term "argument" in php means. Why is it called an "Argument"? Argument to me is having a verbal war with another person. hehe.
     
    Last edited: Apr 20, 2010
    askscript, Apr 20, 2010 IP
  7. krsix

    krsix Peon

    Messages:
    435
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #7
    some developers get pissed off by php easily

    argument in tech-related: 'a reference or value that is passed to a function, procedure, subroutine, command, or program'
     
    krsix, Apr 20, 2010 IP
  8. askscript

    askscript Member

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #8
    ok, so that means

    $big = "you are sexy";

    "you are sexy " is considered an argument to $big. Is that right?
     
    Last edited: Apr 22, 2010
    askscript, Apr 22, 2010 IP
  9. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #9
    No - "you are sexy" is the value of the variable $big.

    However - in this scenario;

    $big = "you are sexy";
    myfunction($big);
    
    function myfunction($var)
    {
    print $var;
    }
    PHP:

    Here, The value in $big is passed as an argument to 'myfunction'.
     
    lukeg32, Apr 22, 2010 IP