Jump to content

Create a link?


taneya

Recommended Posts

I am a real novice w/ PHP.  If I have a field in my database table that is a link (for example - http://www.phpfreaks.com), is there a way to use PHP to turn that URL into a link when displayed on my php page? I'd prefer not to have to the a href tag and info around the link itself into the database table.

 

I certainly welcome any suggestions.

 

Taneya

Link to comment
https://forums.phpfreaks.com/topic/59753-create-a-link/
Share on other sites

Take this example script:

 

<?php
$_socket = mysql_connect('server', 'username', 'password');
mysql_select_db('database');

$result = mysql_query('your select query');
while ($row = mysql_fetch_assoc($result))
{
     print '<a href="' . $result['yourDatabaseLinkColumn'] . '">' . $result['yourDatabaseLinkColumn'] . '</a>';
}
?>

Simply change yourDatabaseLinkColumn to the name of the column in your database that corresponds to the link field.

Link to comment
https://forums.phpfreaks.com/topic/59753-create-a-link/#findComment-297121
Share on other sites

Thank you both for the suggestions! I plan to get back to this tonight and will try it out. May I ask another question though? Let's say one field is site name and another field is URL. What would the code look like if I wanted to show the text of the site name, but make that text a link using the URL in the other field of the table?

Link to comment
https://forums.phpfreaks.com/topic/59753-create-a-link/#findComment-298149
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.