wwconslt Posted April 27, 2011 Share Posted April 27, 2011 Hello Everyone, I'm using PHP with MySQL. One of the fields in the database is website. The code I'm using is as follows: variable: $web=mysql_result($result,$i,"web"); html/php code: <td><font face="Arial, Helvetica, sans-serif"><a href="<? echo "$web"; ?>">Website</a></font></td> What it should do is have the clickable word Website with the correct url from the database. Instead it's repeating the website the page is on. For example it's doing this: http://mywebsite/www.enteredwebsite.com Any help is appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/234910-href-with-web-link-variable-repeating-my-web-site/ Share on other sites More sharing options...
fugix Posted April 27, 2011 Share Posted April 27, 2011 Always get into the habit of using full <?php tags. What is your $I variable? Quote Link to comment https://forums.phpfreaks.com/topic/234910-href-with-web-link-variable-repeating-my-web-site/#findComment-1207229 Share on other sites More sharing options...
QuickOldCar Posted April 27, 2011 Share Posted April 27, 2011 Try this, it's most likely because there is no http:// up front. $web=mysql_result($result,$i,"web"); if (substr($web, 0, 5) != "http:") { $web = "http://$web"; } Quote Link to comment https://forums.phpfreaks.com/topic/234910-href-with-web-link-variable-repeating-my-web-site/#findComment-1207237 Share on other sites More sharing options...
wwconslt Posted April 29, 2011 Author Share Posted April 29, 2011 Thanks!! That did the trick. I'm don't really understand how though. How is the http:// of my main site getting picked up in the first place, so that we have to strip it out? (noob here). Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/234910-href-with-web-link-variable-repeating-my-web-site/#findComment-1207961 Share on other sites More sharing options...
QuickOldCar Posted April 29, 2011 Share Posted April 29, 2011 Well I'll try to explain. It more so that your link in the href is lacking the http:// lets say you use this as a self to server url, or a server path <a href="./">link</a> <a href="../">link</a> <a href="/">link</a> now lets point it to a place on your site, nothing is needed besides a file or script name (this is the same way your domain names were treated) <a href="my-script.php">link</a> or <a href="gallery/">link</a> now when it sees a protocol such as http:// , ftp:// and so on, it knows to go outbound <a href="http://somesite.com">link</a> Quote Link to comment https://forums.phpfreaks.com/topic/234910-href-with-web-link-variable-repeating-my-web-site/#findComment-1207973 Share on other sites More sharing options...
wwconslt Posted April 29, 2011 Author Share Posted April 29, 2011 Excellent, clear explanation. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/234910-href-with-web-link-variable-repeating-my-web-site/#findComment-1207978 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.