Forum Moderators: coopster
I am stuck on a problem, that probaly has an insanely simple solution, but I just can't get it. I have built a mysql db that people can upload their details into, ie name, website, job title etc. Then I have created a php page that queries the database and displays all the results. What I want to know, is how do I format the query to display the result as a hyperlink? Here is an example of the code to display the website field in from the db:
<?php echo $row_rsContent['url'];
How do I modify the code so that it displays 'url' as a hyperlink?
Any help would be greatly appreciated!
Regards,
Ballistix
That sort of worked, except for one thing. Let's say the URL is www.webmasterworld.com. The link it's creating is not to www.webmasterworld.com, but instead to [localhost...]
Any input would really help.
Ballistix
<p><strong>Your website:</strong> h*tp://<input type="text" name="url"></p>
Your website: h*tp://[_______]
So that the user can see that the http:// is not needed. Then when you get the data, before putting it in the DB, check it.
$url = $_POST['url']
if (substr($url, 0, 7) == 'http://')
{
$url = substr($url, 6);
}
Now put the url in the DB knowing that it does not have the http:// at the beginning. Then, for output,
$url = <url you got from the DB>
echo '<a href="http://' . $url . '">My Website</a>';
That's what I would do rather than storing the http:// in the DB.
https shouldn't really be a problem, because the connection should still work, it just won't be secure, perhaps resulting in a redirect.
If you wanted to allow other protocols, you could do the reverse of what I just offered and test for multiple protocols. If no protocol were given, I would add http:// by default.
Still, in this situation where it is meant to be part of a personal profile, along with name, email and such, I would probably just enforce the http just like on WebmasterWorld and let them put a link to a page that gives ftp info if that's what they want.
Tom