Jump to content

URL from MySQL data

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
hudbarnett

hudbarnett

    Newbie

  • Members
  • PipPip
  • 23 posts
Hi Guys

I'm working on a page that shows results from my database, it show in a page the website url and club name. I would like the website url to be a hyperlink that opens into a new window but so far i've had no luck with it.

Below is the code that i'm using:

<?php
$con = mysql_connect("localhost","db_user","pass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("db_name", $con);

$result = mysql_query("SELECT * FROM members");

echo "<table border='1'>
<tr>
<th>Site Address</th>
<th>Club</th>
</tr>";

while($row = mysql_fetch_array($result)) {
    echo "<tr>";
    echo "<td><a target="_blank" href=' . $row['webaddress']}'>{$row['webaddress']}</a></td>";
    echo "<td>" . $row['club'] . "</td>";
    echo "</tr>";
}  echo "</table>";

mysql_close($con);
?> 


#2
hudbarnett

hudbarnett

    Newbie

  • Members
  • PipPip
  • 23 posts
Hi all

managed to get this line to show the data that i want but i still need it to open in a new window when clicked on

echo "<td><a href='" . $row['webaddress'] . "'>" . $row['webaddress'] . "</a></td>";

Can anyone help? I have tried adding target="_blank" just before the href but it didn't run the link?

Please Help :)

Thanks

#3
hudbarnett

hudbarnett

    Newbie

  • Members
  • PipPip
  • 23 posts
There is light at the end of the tunnel, i managed to get it working :)

I think i now understand what i was doing wrong

echo "<td><a target='_blank' href='" . $row['webaddress'] . "'>" . $row['webaddress'] . "</a></td>";

Is there a why where i can force the http:// as part of the row?

Thanks

Hud

#4
hudbarnett

hudbarnett

    Newbie

  • Members
  • PipPip
  • 23 posts
Managed to sort this out, it was easy :) I must be starting to learn

echo "<td><a target='_blank' href=http://" . $row['username'] . ">" . $row['username'] . "</a></td>";

Thanks

Hud

#5
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
Although, if http:// is included in the link, you will have dual http://, and that won't work either. so, you need to make sure no http:// is in your database, or, you need to check whether there is a http:// or not before adding it.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#6
hudbarnett

hudbarnett

    Newbie

  • Members
  • PipPip
  • 23 posts
thank you, i will look at my code and fix it :)