Tutorial :Creating a single hyperlink from 2 mysql table entries using php



Question:

I have a mysql table containing the values for 'display' and 'link'.

I'd like to pull these into a php file that displays the 'display' value which hyperlinks to the 'link' value

I have already connected to the database and selected the appropriate rows to display, but I'm at a loss on how to create the php for this..

As you can probably tell, I'm a complete noob so simplicity is appreciated in any answers.. thanks for the help!


Solution:1

like so?

$row = mysql_fetch_assoc($result);  echo '<a href="'.$row["link"].'">'.$row["display"].'</a>';  


Solution:2

One addition to the previous posters code. You'll want to escape the values before outputting them to prevent html injection attacks (and general wonkiness if special characters are in the links or titles).

$row = mysql_fetch_assoc($result);  echo '<a href="'.htmlspecialchars($row["link"]_.'">'. htmlspecialchars($row["display"]).'</a>';  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »