jwb
jwb

Reputation: 17

Creating a single hyperlink from 2 mysql table entries using php

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!

Upvotes: 0

Views: 3016

Answers (2)

Daniel Von Fange
Daniel Von Fange

Reputation: 6071

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>';

Upvotes: 2

davethegr8
davethegr8

Reputation: 11595

like so?

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

Upvotes: 3

Related Questions