Using a variable in a hyperlink

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dan Gaffey
    New Member
    • Apr 2011
    • 16

    Using a variable in a hyperlink

    I'm trying to wite a code that can take a web address from a variable and out it into a hyperlink.

    This is what I have so far:

    Code:
    // display the results returned
      
      while ($row= mysql_fetch_array($result)) {
      $title = $row["song_name"];
      $artist = $row["artist"];
      $genre = $row["genre"];
      $SongID = $row["SongID"];
      $Buy = $row["purchase_link"];
      
      echo "$count.) $title" ;
      echo " - " ;
      echo  "$artist"  ;
      print( '<a href="$Buy">Buy this track</a>' );
      $count++ ;
      }
    This doesn't work (stating the obvious or I woudn't be asking!), so any ideas, tips etc.?
    Last edited by Dan Gaffey; Apr 6 '11, 05:32 PM. Reason: Missing code tags
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    use either " instead of ' or take the variables out of the string or use printf().
    Code:
    printf('<a href="%s">Buy this track</a>', $Buy);

    Comment

    • Dan Gaffey
      New Member
      • Apr 2011
      • 16

      #3
      Works perfectly! thanks a lot for your help

      Comment

      Working...