2016-09-30 151 views
0

我正在處理一個php代碼,我在窗口值和一個文件到頁面呼應。我有這個工作正常,但我想實現一個按鈕時重新啓動按鈕將再次顯示該頁面沒有回聲。任何建議或更好的方法來做到這一點?刷新頁面與Php

<html> 
<head> 

</head> 
<body> 
<div class="page"> 
    <h1>File Loader</h1> 
    <form method="post"> 
     <label>Name:</label><input type="text" name="name"></br> 

     <label>Date:</label><input type="text" name="date"></br> 

     <input type="submit" name="submit" value="Submit"> 
     <input type="button" name="startOver" value="Start Over" onclick="phpfile.php"></br> 
    </form> 
</div> 

<?php 
if ($_POST['submit']) { 

    $name = $_POST['name']; 
    $date = $_POST['date']; 

    echo "Name: $name</br></br>"; 
    echo "Date: $date</br>"; 

    $file_handle = fopen("file.csv", "r"); 


     while (!feof($file_handle)) { 

      $fields_of_text = fgetcsv($file_handle, 2024); 

      $f = $fields_of_text; 
      $format = "%s %s %s %s %s %s %s %s %s %s %s"; 
      echo "<br>" . sprintf($format, $f[0], $f[1], $f[2], $f[3], $f[4], $f[5], $f[6], $f[7], $f[8], $f[9], $f[10]); 

      echo "<br>"; 

      echo "<br>"; 
      echo "<br>"; 
     } 

     fclose($file_handle); 


} else { 
    header("Location: phpfile.php"); 
} 
?> 
</div> 
</body> 
</html> 
+0

你是說這段代碼不起作用嗎? – nogad

+0

我不知道如何重新啓動按鈕來重新加載頁面URL。 – user320522

+0

對於PHP你會使用'header(「Location:'但你似乎想要一個JS解決方案? – nogad

回答

0

你可以很容易地使用查詢字符串/後params。

您可以像下面一樣使用$ _GET,或者您可以使用隱藏的輸入,並使用onclick和javascript將其更改爲1或2,如果您需要使用post。

</head> 
<body> 
<div class="page"> 
    <h1>File Loader</h1> 
    <form method="post"> 
     <label>Name:</label><input type="text" name="name"></br> 

     <label>Date:</label><input type="text" name="date"></br> 


     <input type="button" value="Submit" onclick="window.location.href='phpfile.php?SubmitType=1';"> 
     <input type="button" value="Start Over" onclick="window.location.href='phpfile.php?SubmitType=2';"> 

     </br> 
    </form> 
</div> 

<?php 
if ($_GET['SubmitType'] == '1') { 



    $name = $_POST['name']; 
    $date = $_POST['date']; 

    echo "Name: $name</br></br>"; 
    echo "Date: $date</br>"; 

    $file_handle = fopen("file.csv", "r"); 


     while (!feof($file_handle)) { 

      $fields_of_text = fgetcsv($file_handle, 2024); 

      $f = $fields_of_text; 
      $format = "%s %s %s %s %s %s %s %s %s %s %s"; 
      echo "<br>" . sprintf($format, $f[0], $f[1], $f[2], $f[3], $f[4], $f[5], $f[6], $f[7], $f[8], $f[9], $f[10]); 

      echo "<br>"; 

      echo "<br>"; 
      echo "<br>"; 
     } 

     fclose($file_handle); 


    } 
    else { 
     header("Location: phpfile.php"); 
     exit(); 
    } 
?> 
</div> 
</body> 
</html>