Welcome to WebmasterWorld Guest from

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)

5+ Year Member

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:


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 "";




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

10+ Year Member

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

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


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

5+ Year Member

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)

5+ Year Member

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)

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

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.


Featured Threads

Hot Threads This Week

Hot Threads This Month