Welcome to WebmasterWorld Guest from 54.227.1.130

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

     

Tylee

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:

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

jezra

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

10+ Year Member



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>

Tylee

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?

Tylee

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.

coopster

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