如何制作一个按钮在PHP上打开一个新选项卡中的链接

时间:2016-03-13 12:44:19

标签: php button

有没有办法在php中创建一个按钮,在新标签中打开一个链接? 我通过链接打开iframe来解决问题 但现在我想在页面顶部添加一个返回主页的按钮 我怎么能这样做

<?php
$host="localhost"; // Host name 
$username="publiadd_publix"; // Mysql username 
$password="1a3g7893fsh"; // Mysql password 
$db_name="publiadd_urlrotator"; // Database name 
$tbl_name="url_rotator"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

     $query = 'SELECT * FROM url_rotator ORDER BY root_name DESC LIMIT 10';
     $result = mysql_query($query) or die("<b>A fatal MySQL error occured</b>.<br />Query: ".$query."<br />Error: (".mysql_errno().") ".mysql_error());
// Print Title

print '<center>'."All Rotator In Our Network! ".'</center>';
print '<center>'."---------------------------".'</center>';
     while ($row = mysql_fetch_assoc($result)) { 
          $id = $row['id'];
          $root_name = $row['root_name'];
          $root_url1 = $row['root_url1'];
          $root_url2 = $row['root_url2'];
          $root_url3 = $row['root_url3'];
          $root_url4 = $row['root_url4'];
          $root_url5 = $row['root_url5'];
          $root_url6 = $row['root_url6'];
          $root_url7 = $row['root_url7'];
          $root_url8 = $row['root_url8'];
          $root_url9 = $row['root_url9'];
          $root_url10 = $row['root_url10'];
echo '<center>'.$row['id'] . " | " . $row['root_name'] . " | " .'</center>' ;
echo '<center>'.$row['root_url1'] . " * " .'</center>' ;
echo '<center>'.$row['root_url2'] . " * " .'</center>' ;
echo '<center>'.$row['root_url3'] . " * " .'</center>' ;
echo '<center>'.$row['root_url4'] . " * " .'</center>' ;
echo '<center>'.$row['root_url5'] . " * " .'</center>' ;
echo '<center>'.$row['root_url6'] . " * " .'</center>' ;
echo '<center>'.$row['root_url7'] . " * " .'</center>' ;
echo '<center>'.$row['root_url8'] . " * " .'</center>' ;
echo '<center>'.$row['root_url9'] . " * " .'</center>' ;
echo '<center>'.$row['root_url10'] . " * " .'</center>' ;
echo  "<iframe src=\"{$root_url1}\" style=\"background: #fff;\" frameborder=\"0\" height=\"450\" scrolling=\"auto\" width=\"100%\"></iframe>";
echo  "<iframe src=\"{$root_url2}\" style=\"background: #fff;\" frameborder=\"0\" height=\"450\" scrolling=\"auto\" width=\"100%\"></iframe>";
echo  "<iframe src=\"{$root_url3}\" style=\"background: #fff;\" frameborder=\"0\" height=\"450\" scrolling=\"auto\" width=\"100%\"></iframe>";
echo  "<iframe src=\"{$root_url4}\" style=\"background: #fff;\" frameborder=\"0\" height=\"450\" scrolling=\"auto\" width=\"100%\"></iframe>";
echo  "<iframe src=\"{$root_url5}\" style=\"background: #fff;\" frameborder=\"0\" height=\"450\" scrolling=\"auto\" width=\"100%\"></iframe>";
echo  "<iframe src=\"{$root_url6}\" style=\"background: #fff;\" frameborder=\"0\" height=\"450\" scrolling=\"auto\" width=\"100%\"></iframe>";
echo  "<iframe src=\"{$root_url7}\" style=\"background: #fff;\" frameborder=\"0\" height=\"450\" scrolling=\"auto\" width=\"100%\"></iframe>";
echo  "<iframe src=\"{$root_url8}\" style=\"background: #fff;\" frameborder=\"0\" height=\"450\" scrolling=\"auto\" width=\"100%\"></iframe>";
echo  "<iframe src=\"{$root_url9}\" style=\"background: #fff;\" frameborder=\"0\" height=\"450\" scrolling=\"auto\" width=\"100%\"></iframe>";
echo  "<iframe src=\"{$root_url10}\" style=\"background: #fff;\" frameborder=\"0\" height=\"450\" scrolling=\"auto\" width=\"100%\"></iframe>";
     }//end while
// close MySQL connection 
mysql_close();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
<link rel="stylesheet" href="style.css" type="text/css" />
//<a href="<?php echo $root_url10 ?>"><?php echo $root_url10 ?></a>
</head>
<body bgcolor="#ffffff">
<center><br><br><form>
<input type="button" value="Back" onclick="window.location.href='http://bitcoinrotator.publiadds.org.pt/login-registration/home.php'" />
</form></center>
</body>

1 个答案:

答案 0 :(得分:1)

只需用window.open替换window.location.href。

试试这个:

 <?php
     $host="localhost"; // Host name 
     /* Codes */
      $result = mysql_query($query) or die("<b>A fatal MySQL error occured</b>.<br />Query: ".$query."<br />Error: (".mysql_errno().") ".mysql_error());
    // Print Title
 ?>
 <!-- Place your button below, separated from PHP tag -->
 <input type="button" value="Back"  onclick="window.open('http://bitcoinrotator.publiadds.org.pt/login-registration/home.php')" />
 <center>'."All Rotator In Our Network! ".'</center>
 <center>'."---------------------------".'</center>

<?php 
 /* While loop and other codes */
?>