Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Sep 2007
    Posts
    809
    Thanks
    5
    Thanked 2 Times in 2 Posts

    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???

  • #2
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,954
    Thanks
    9
    Thanked 724 Times in 718 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Sep 2007
    Posts
    809
    Thanks
    5
    Thanked 2 Times in 2 Posts
    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?

  • #4
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    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?

  • #5
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,954
    Thanks
    9
    Thanked 724 Times in 718 Posts
    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?

  • #6
    Regular Coder
    Join Date
    Sep 2007
    Posts
    809
    Thanks
    5
    Thanked 2 Times in 2 Posts
    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://


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •