Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-27-2009, 12:47 PM   PM User | #1
greens85
Regular Coder

 
Join Date: Sep 2007
Posts: 809
Thanks: 5
Thanked 2 Times in 2 Posts
greens85 is an unknown quantity at this point
Linking to a website through PHP

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 Code:
<?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???
greens85 is offline   Reply With Quote
Old 10-27-2009, 12:56 PM   PM User | #2
SB65
Senior Coder

 
Join Date: Feb 2009
Location: West Yorkshire
Posts: 2,813
Thanks: 9
Thanked 681 Times in 675 Posts
SB65 will become famous soon enoughSB65 will become famous soon enough
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.
SB65 is online now   Reply With Quote
Old 10-27-2009, 01:37 PM   PM User | #3
greens85
Regular Coder

 
Join Date: Sep 2007
Posts: 809
Thanks: 5
Thanked 2 Times in 2 Posts
greens85 is an unknown quantity at this point
Quote:
Originally Posted by SB65 View Post
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?
greens85 is offline   Reply With Quote
Old 10-27-2009, 02:05 PM   PM User | #4
tomws
Senior Coder

 
tomws's Avatar
 
Join Date: Nov 2007
Location: Arkansas
Posts: 2,644
Thanks: 29
Thanked 330 Times in 326 Posts
tomws will become famous soon enoughtomws will become famous soon enough
There's nothing magical about the http:// part - it's just a string:
PHP Code:
echo '<a href="http://' $row['website'] . '">' $row['website'] . '</a>'
__________________
Are you a Help Vampire?
tomws is offline   Reply With Quote
Old 10-27-2009, 02:06 PM   PM User | #5
SB65
Senior Coder

 
Join Date: Feb 2009
Location: West Yorkshire
Posts: 2,813
Thanks: 9
Thanked 681 Times in 675 Posts
SB65 will become famous soon enoughSB65 will become famous soon enough
You could just prepend it in the code:

PHP 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?
SB65 is online now   Reply With Quote
Old 10-27-2009, 02:15 PM   PM User | #6
greens85
Regular Coder

 
Join Date: Sep 2007
Posts: 809
Thanks: 5
Thanked 2 Times in 2 Posts
greens85 is an unknown quantity at this point
Quote:
Originally Posted by SB65 View Post
You could just prepend it in the code:

PHP 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://
greens85 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:27 AM.


Advertisement
Log in to turn off these ads.