2016-04-12 10 views
2

最初の実行テーブルが表示され、outs_print.phpファイルが再度実行されたときにouts_print.phpファイルが表示され、同時に同じタブに表示されます。ボタンをクリックした後、テーブルを表示して新しいウィンドウを開く

ボタンをクリックした後、新しいタブにテーブル(outs_print.phpファイル)を表示します。

<?php 

    $connection = mysql_connect("localhost", "root", ""); 
    $db = mysql_select_db("prs", $connection); 
    if(isset($_POST['submit'])){  
    $name = $_POST['name']; 
    $from = $_POST['from']; 
    $to = $_POST['to']; 
    if($name !=''||$from !=''||$to !='') 
    { 
?> 

<html> 
<body> 
    <table border="1" bordercolor="#d6d6d6" class="tabl"> 
    <thead bgcolor="#FAFAFA"> 
    <tr> 
    <th>No</th> 
    <th>Date</th> 
    <th>Name</th> 
    <th>Price</th> 
    </tr> 
    </thead> 

    <tbody> 

    <?php 
     $sql = "SELECT * FROM out WHERE (date between '$from' and '$to') AND (name = '$name')"; 
     $records=mysql_query($sql); 
     while($out=mysql_fetch_assoc($records)) 
     { 
      echo "<tr>"; 
      echo "<td>".$out['no']."</td>"; 
      echo "<td>".$out['date']."</td>"; 
      echo "<td>".$out['name']."</td>"; 
      echo "<td>".$out['price']."</td>"; 
      echo "</tr>"; 
     } 
    ?> 

      <script type="text/javascript"> 
      alert("Okay"); 
      var win = window.open("out_print.php", "out_print.php"); 
      win.focus(); 
      </script> 

    <?php 
     } 
    } 
    ?> 

    </tbody> 
    </table> 

</body> 
</html> 

答えて

1

これ以外の回答は右のトラックにありますが、target="_blank"は各フォームの送信時に新しいタブ/ウィンドウを作成します。

フォームの最初の提出時に新しいタブ/ウィンドウを開始し、最初の提出時に作成されたタブ/ウィンドウにフォームの結果を返す場合は、名前はそれを行います。 `ターゲット= "_ブランク"`すべての提出のための新しいタブ/ウィンドウを起動します除き

<form name="out_print" method="post" action="out_print.php" target="out_print_response"> 
.... 

http://www.w3schools.com/tags/att_form_target.asp

0

outs_print.php

<!doctype html> 
<body> 
    <form name="out_print" action="out_print.php" method="post"> 
    <table class="table_1"> 
    <tr><td><label>Date Range From</label></td> 
    <td><input type="date" name="from" /></td> 

    <td><label>To</label></td> 
    <td><input type="date" name="to"/></td></tr> 

    <tr><td><label>Name</label></td> 
    <td><input type="text" name="name" /></td></tr></table> 

    <input type="submit" name="submit" value="Search" onclick="myFunction();" class="button3"/> 
    <script> 
    function myFunction() 
    { 
    document.out_print.action = "outs_print.php"; 
    document.out_print.submit();     
    } 
    </script> 
</form> 
</body> 
</html> 

ジャスト= "_ブランク" のフォーム要素に:)

http://www.w3schools.com/tags/tag_form.asp

+0

。 –

+0

これで、sumit width removeAttribute(target)の後に削除することができます –

+0

しかし、最初の投稿が新しいタブ/ウィンドウで開き、それ以降の投稿はフォームが送信されたタブ/ウィンドウで開きます。これは、OPが望んでいた動作ではありません。私の答えを見てください。 –

0

このようtarget="_blank"を追加するターゲットを追加:

<form name="out_print" action="out_print.php" method="post" target="_blank"> 

formのtarget属性は、フォームの送信後に受け取る応答を表示する場所を指定します。 target="_blank"new tabに応答を表示します。

これが役に立ちます。

+0

'target =" _ blank "を除いて、すべての投稿に対して新しいタブ/ウィンドウが起動します。 –