teknospr Posted March 3, 2011 Share Posted March 3, 2011 Hello: I wrote the following script. It is working fine, I just need the links to open in a blank window. Any help will be appreciated. <html> <body> <?php $connection = mysql_connect("localhost", "username", "password"); mysql_select_db("articles", $connection); $query="SELECT * FROM articles WHERE id=1"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <table border="1" cellspacing="2" cellpadding="2"> <tr> <th><font face="Arial, Helvetica, sans-serif">Article</font></th> <th><font face="Arial, Helvetica, sans-serif">Year</font></th> <th><font face="Arial, Helvetica, sans-serif">Description</font></th> <th><font face="Arial, Helvetica, sans-serif">Location</font></th> </tr> <?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"article"); $f2=mysql_result($result,$i,"year"); $f3=mysql_result($result,$i,"description"); $f4=mysql_result($result,$i,"location"); $f5=mysql_result($result,$i,"link") ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo "<a href=".$f5.">".$f4."</a>"; ?></font></td> </tr> <tr> </tr> <?php $i++; } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/229512-open-href-in-new-blank-window/ Share on other sites More sharing options...
cunoodle2 Posted March 3, 2011 Share Posted March 3, 2011 Did you try searching Google? If I take your title of "open href in new blank window" and paste it into Google the first result shows you how to do it.. http://www.google.com/#hl=en&q=open+href+in+new+blank+window Link to comment https://forums.phpfreaks.com/topic/229512-open-href-in-new-blank-window/#findComment-1182471 Share on other sites More sharing options...
teknospr Posted March 3, 2011 Author Share Posted March 3, 2011 Yes, but I keep getting errors no matter the syntax. Hoping someone could identify how it should be properly written. Link to comment https://forums.phpfreaks.com/topic/229512-open-href-in-new-blank-window/#findComment-1182474 Share on other sites More sharing options...
Krash Posted March 3, 2011 Share Posted March 3, 2011 <a href=".$f5." target="_new">".$f4."</a> Link to comment https://forums.phpfreaks.com/topic/229512-open-href-in-new-blank-window/#findComment-1182475 Share on other sites More sharing options...
Muddy_Funster Posted March 3, 2011 Share Posted March 3, 2011 Please read the rules : all code is to be posted within the forums [ ]...[ ] tags. answer to your question - just include target="_blank" at the end of the html for the anchor (just after the href="") however, your problem will be that you arn't concatenating your strings properly. Have a go at this: <td><font face="Arial, Helvetica, sans-serif"><?php echo "<a href=\"$f5\" target=\"_blank\">$f4</a>"; ?></font></td> should get it Link to comment https://forums.phpfreaks.com/topic/229512-open-href-in-new-blank-window/#findComment-1182478 Share on other sites More sharing options...
cunoodle2 Posted March 3, 2011 Share Posted March 3, 2011 Quote <a href=".$f5." target="_new">".$f4."</a> That will not work as the double quotes will escape the echo. Try this.. <?php echo "<a href=\"$f5\" target=\"_blank\">$f4</a>"; ?> Link to comment https://forums.phpfreaks.com/topic/229512-open-href-in-new-blank-window/#findComment-1182479 Share on other sites More sharing options...
Pikachu2000 Posted March 3, 2011 Share Posted March 3, 2011 You need to escape quotes of the same type used to enclose a string in php. <?php echo "<a href=\"$f5\" target=\"_blank\">$f4</a>"; ?> Link to comment https://forums.phpfreaks.com/topic/229512-open-href-in-new-blank-window/#findComment-1182480 Share on other sites More sharing options...
teknospr Posted March 3, 2011 Author Share Posted March 3, 2011 It worked. I really appreciate. I had been pulling my hair for two hours and it took you guys 2 minutes. Link to comment https://forums.phpfreaks.com/topic/229512-open-href-in-new-blank-window/#findComment-1182481 Share on other sites More sharing options...
teknospr Posted March 4, 2011 Author Share Posted March 4, 2011 Thanks. Im gonna try and make the rows display in white and gray or any other two colors. Wish me luck (Im a newbie). Link to comment https://forums.phpfreaks.com/topic/229512-open-href-in-new-blank-window/#findComment-1182630 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.