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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.