Welcome to WebmasterWorld Guest from 23.20.79.227

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

help opening in new window

php mysql resulted link open in new window when clicked

     
5:19 pm on Apr 1, 2009 (gmt 0)

New User

5+ Year Member

joined:Apr 1, 2009
posts: 3
votes: 0

What I am needing is someone to teach me how to open the link that is returned from mysql db in a new separate window.

Here is my code:

<?php

mysql_connect("localhost", $dbUser, $dbPassword);
mysql_select_db("contents") or die(mysql_error());

echo "";

$get_links = mysql_query("SELECT * FROM groups ORDER BY group_name");
while ($array = mysql_fetch_array($get_links))

{
echo "<br><br><a href=\"$array[group_URL]\">$array[group_name]</a> ";
if ($array[group_desc]<>"")
{echo", $array[group_desc]";};

}

echo "";

?>

thanks,

6:57 pm on Apr 1, 2009 (gmt 0)

Full Member

10+ Year Member

joined:Feb 4, 2004
posts: 215
votes: 0


You need to set the "target" property of your link to "_blank".

example
<a href="http://www.example.com/" target="_blank">go to example</a>

7:06 pm on Apr 1, 2009 (gmt 0)

New User

5+ Year Member

joined:Apr 1, 2009
posts:3
votes: 0


I've tried that and all I get is a blank page. For some reason it doesn't like - maybe beacuse of the
$array[group_URL] is not a direct http://www.example.com/
In mysql db the url is: http://www.example.com/

Any other suggestions to work around?

8:17 pm on Apr 1, 2009 (gmt 0)

New User

5+ Year Member

joined:Apr 1, 2009
posts:3
votes: 0


Figured it out - don't know why but it prefers the target before the href code like below:

echo "<br><br><a target=\"_blank\" href=\"$array[group_URL]\">$array[group_name]</a>";

Might have also been the problem of the missing \ after target= also.

Anyway - it works!
thanks jezra for the help.

8:36 pm on Apr 1, 2009 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12541
votes: 1


It was the latter. You must have the syntax correct. You could turn up error_reporting [php.net] in your test environment and you will catch these errors. Also don't forget that you can always use the W3 validator on your rendered HTML to make sure you do not have any issues.

Welcome to WebmasterWorld, Tylee.