Go Back  Xtreme Visual Basic Talk > Other Languages > Web Programming > how to include a web address in a PHP string


Reply
 
Thread Tools Display Modes
  #1  
Old 06-01-2012, 06:27 AM
starmanMike starmanMike is offline
Centurion
 
Join Date: Oct 2005
Location: near Norwich, UK
Posts: 174
Default how to include a web address in a PHP string


HI,
First off, this has nothing to do with the PHP include() function!
OK... I have a mysql database (currently on my WAMP webserver) which contains members' website and email addresses, so the contents of the 'website' field could be a string like:
http://www.starman.co.uk (not underlined in DB, just straight text, but the link keeps getting put in, even if I do 'remove link'!)
there is also a search page where members can search for other members, and query this DB. This all works perfectly.
I would really like to be able to display a member's website address as a clickable link, but can't get my head round the way to format it. At the moment, the web and email addresses are being properly returned from the DB query, but only as plain text.
Sure, savvy users can copy and paste this into the browser's address bar, but it would be really neat if the addresses could be formatted as clickable links.
Anyone have any suggestions how to do that?
Code is:
Code:
while ($row = mysql_fetch_assoc($result)) 
			{
			echo "<b>Club: </b>" .$row['club']. "<br>";
			echo "<b>Venue: </b>". $row['venue']. "<br>";
			echo "<b>Description: </b>". $row['description'];
			echo "<br>";
			echo "<b>Contact: </b>" .ucwords($row['fname']);
			echo "<br>";
			echo "<b>Telephone: </b>" .$row['landline'];
			echo "<br>";
			echo "<b>Mobile: </b>" .$row['mobile'];
			echo "<br>";
			echo "<b>Email: </b>" .$row['email'];
			echo "<br>";
			echo "<b>Website: </b>".$row['website'];
			echo "<hr width=100%><br>";
			}
And, as I say, this all works. No problem with the 'actual' coding, just how to render those last two rows from the DB as clickable links!
Reply With Quote
  #2  
Old 06-01-2012, 08:59 AM
DrPunk's Avatar
DrPunk DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,275
Default

I don't know a great deal about this stuff, but I think you want to be echoing an <a> tag with the href attribute.

See -> http://www.w3schools.com/tags/att_a_href.asp

My guess would be something like...
Code:
echo "<b>Website: </b> <a href=" .$row['website'] ">";
... but don't quote me on that syntax. I have no means of testing it either.
__________________
There are no computers in heaven!
Reply With Quote
  #3  
Old 06-01-2012, 10:13 AM
starmanMike starmanMike is offline
Centurion
 
Join Date: Oct 2005
Location: near Norwich, UK
Posts: 174
Default

Thanks, drPunk!
Your solution definitely sent me in the right direction. I have just tried it out with success, so for the use of anyone else who may have the same problem, here's what works:
Code:
if ($row['website']=="")
			{
				echo "";
			}
			else
			{
			echo "<b>Website: </b><a href=".$row['website'].">Here</a>";	
			}
- We need an option to cater for those occasions where there is no web address in the DB, plus some link text, and the closing </a> tag as well.
Reply With Quote
  #4  
Old 07-09-2012, 11:37 AM
Ashtechsmith Ashtechsmith is offline
Newcomer
 
Join Date: May 2012
Location: Ahmedabad, Gujrat, India
Posts: 5
Default

An Include Example

<html>
<body>
<a href="http://www.example.com/index.php">Home</a> -
<a href="http://www.example.com/about.php">About Us</a> -
<a href="http://www.example.com/links.php">Links</a> -
<a href="http://www.example.com/contact.php">Contact Us</a> <br />

<?php include("menu.php"); ?>
<p>This is my home page that uses a common menu to save me time when I add
new pages to my website!</p>
</body>
</html>
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->