SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    changing a variable value into url value

    url parameter using a php variable

    Code:
    <?
    $a=my;
    ?>
    I have a variable with the code above.


    I like to make a link with the text "my"
    The following code works fine.
    Code:
    <?
    $a=my;
    ?>
    <a href='next.php?q=my'>next</a>
    Now I like to make a link with a variable "$a" instead of the text "my"

    The code below doesn't work correctly but I hope it will show what I want.
    Code:
    <?
    $a=my;
    
    <a href='next.php?q=$a'>next</a>
    
    ?>
    How can I make it work correctly?

  2. #2
    SitePoint Addict
    Join Date
    May 2006
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <?
    $a=my;
    ?>
    
    <a href='next.php?q=<?=$a?>'>next</a>
    I think ...

    Rgds

  3. #3
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by accelerator View Post
    Code:
    <?
    $a=my;
    ?>
    
    <a href='next.php?q=<?=$a?>'>next</a>
    I think ...

    Rgds
    Thank you, it works fine.

  4. #4
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    You really should do:

    PHP Code:
    <?php 
    $a 
    'my';
    ?>
    <a href="next.php?q=<?php echo $a;?>">next</a>
    Ryan B | My Blog | Twitter

  5. #5
    SitePoint Addict Iceman90's Avatar
    Join Date
    Mar 2006
    Location
    Calgary, Alberta, Canada
    Posts
    392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rguy84 View Post
    You really should do:

    PHP Code:
    <?php 
    $a 
    'my';
    ?>
    <a href="next.php?q=<?php echo $a;?>">next</a>
    Yes, as rguy said, it's best to use the opening PHP tag as <?php and to echo the variable for output.


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
  •