Links and variables

Discussion in 'PHP' started by Handsofmodder, Aug 2, 2008.

  1. #1
    Hi! I need help adding a variable to a link. Here's the code

    <?php
    $row="sleep";
    print '<a href="page.php?">Shoe</a>';
    
    
    
    ?>
    PHP:
    I want to add it right after the ?
     
    Handsofmodder, Aug 2, 2008 IP
  2. Jasber

    Jasber Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Are you trying to append it after page.php?

    You can break in and out of quotes as you please and append strings together with a period (.).

    For for example:

    print '<a href="page.php?' . $row . '">Shoe</a>';
    PHP:
    Alternatively you could do

    print '<a href="page.php?{$row}">Shoe</a>';
    PHP:
     
    Jasber, Aug 2, 2008 IP
  3. Handsofmodder

    Handsofmodder Peon

    Messages:
    177
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It works! But I have another question. I also want to display the variable inside the URL into another page. Here's the code for the other page

    <?php
    $dude=$_GET['$row'];
    print $dude;
    ?>
    PHP:
     
    Handsofmodder, Aug 2, 2008 IP
  4. Handsofmodder

    Handsofmodder Peon

    Messages:
    177
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    never mind, got it! here's the code
    <?php
    $row="sleep";
    print '<a href="page.php?brand=' . $row . '">Shoe</a>';
    
    
    ?>
    PHP:
    and here's the code for the page.php
    <?php
    $dude=$_GET['brand'];
    print $dude;
    ?>
    PHP:
     
    Handsofmodder, Aug 2, 2008 IP
  5. jpinheiro

    jpinheiro Peon

    Messages:
    1,211
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    0
    #5
    Ok Look At this Below;


    This is /index.php
    <?php
    $row="sleep";
    print '<a href="page.php?{$row}">Shoe</a>';
    
    
    
    ?>
    PHP:
    This is /page.php?sleep
    
    <?php include("menu.php");
    $dude=$_GET['$row'];
    print $dude;
    ?>
    PHP:
    Hope this helps :0
     
    jpinheiro, Aug 2, 2008 IP