简体   繁体   中英

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!

like so?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM