...

View Full Version : Linking to a website through PHP



greens85
10-27-2009, 12:47 PM
Hi all,

I have a piece of code which echo's out a website URL and is linked, however its displaying the URL as:

http://www.mydomain.co.uk/directory/www.externalurl.com

whereas I want to just echo the external url...

The code is:


<?php
$query = "SELECT * FROM teachingagencies_directory WHERE agencyname LIKE '%$agencyname%' AND region LIKE '%$region%' AND address LIKE '%$city%' AND address LIKE '%$postcode%' $limit";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array ($result)) {
$i++;
if ($i & 1) {
echo "
<div class='color1'>
<a href='agencydetails.php?Name=" . $row['agencyname'] . "'>" . $row['agencyname'] . "</a>
<br/>
<br/>
<span class='bold'>Address:</span> <span class='normalfont'>" . $row['address'] . "</span>
<br/>
<span class='bold'>Telephone:</span> <span class='normalfont'>" . $row['telephone'] . "</span>
<br/>
<span class='bold'>Website:</span> <span class='normalfont'><a href='" . $row['website'] . "'>" . $row['website'] . "</a></span>
<br/>
<br/>
</div>";
}
else {
echo "
<div class='color2'>
<a href='agencydetails.php?Name=" . $row['agencyname'] . "'>" . $row['agencyname'] . "</a>
<br/>
<br/>
<span class='bold'>Address:</span> <span class='normalfont'>" . $row['address'] . "</span>
<br/>
<span class='bold'>Telephone:</span> <span class='normalfont'>" . $row['telephone'] . "</span>
<br/>
<span class='bold'>Website:</span> <span class='normalfont'><a href='" . $row['website'] . "'>" . $row['website'] . "</a></span>
<br/>
<br/>
</div>";
}
}
?>

The $row['website'] references a field in the database that contains the url in question - i.e. www.codingforums.com.

Can anyone see why this maybe happening??? :confused:

SB65
10-27-2009, 12:56 PM
What's the format of the website field - is it just www.example.com?
If so you probably need to insert "http://" before the web address.

greens85
10-27-2009, 01:37 PM
What's the format of the website field - is it just www.example.com?
If so you probably need to insert "http://" before the web address.

Hey,

Yeah the format is just www.example.com... is there anyway to append http:// to all records, rather than doing the records one by one?

tomws
10-27-2009, 02:05 PM
There's nothing magical about the http:// part - it's just a string:

echo '<a href="http://' . $row['website'] . '">' . $row['website'] . '</a>';

SB65
10-27-2009, 02:06 PM
You could just prepend it in the code:


echo "<span class='bold'>Website:</span> <span class='normalfont'><a href='http://" . $row['website'] . "'>" . $row['website'] . "</a></span>"

I'm assuming here that you want the actual display just to be www.example.com, and just correct the href?

greens85
10-27-2009, 02:15 PM
You could just prepend it in the code:


echo "<span class='bold'>Website:</span> <span class='normalfont'><a href='http://" . $row['website'] . "'>" . $row['website'] . "</a></span>"

I'm assuming here that you want the actual display just to be www.example.com, and just correct the href?

Thanks for the reply guys... I will prepend it as I don't really want to display the http://



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum