2016-11-07 171 views
0

我寫了這段代碼,點擊提交按鈕後,它不會顯示數據表。我檢查過nazwa1是否包含一些字符串,但不會顯示任何內容。我是PHP和HTML中的新成員,所以我不確定這是不錯的代碼。我閱讀了一些網站,我認爲我的代碼看起來不錯。我到處尋找答案,我什麼也沒找到。感謝幫助。PHP表不顯示數據

 <?php 

       $link=mysqli_connect(connect_data); 

        if(mysqli_connect_errno()){ 
        printf("Nie udało się połączyć: %s", mysqli_connect_error()); 
        exit();}; 

     echo "<div class=\"row\">"; 
      $query = "SELECT Distinct Nazwa FROM vDane "; 
      $result = mysqli_query($link, $query); 
       echo "<div class=\"col-xl-12 marginesy\">"; 
       echo "<div class=\"row\">"; 
        echo "<div class=\"col-xl-3\">"; 
         echo "<select name=\"nazwa1\" class=\"form-control form-control-sm\" placeholder=\"nazwa1\">"; 
         echo "<option value=\"Pracownik\">Pracownik</option>"; 
         while($row = mysqli_fetch_array($result)){ 
          echo "<option value=".$row['Nazwa'].">" .$row['Nazwa']. "</option>"; 

         } 
         echo "</select>"; 
        echo "</div>"; 
      $query = "SELECT Distinct Date FROM vDane "; 
      $result = mysqli_query($link, $query); 
        echo "<div class=\"col-xl-3\">"; 
         echo "<select class=\"form-control form-control-sm\" name=\"Date\" placeholder=\"Date\">"; 
         echo "<option value=\"Data\">Data</option>"; 
         while($row = mysqli_fetch_array($result)){ 
          echo "<option value=".$row['Date'].">" .$row['Date']. "</option>"; 

         }      
         echo "</select>"; 
         //$first_option = $_POST(['Date']); 

        echo "</div>"; 
        echo "<div class=\"col-xl-3\">"; 
         echo "<select class=\"form-control form-control-sm\" name=\"data\" placeholder=\"Data\">"; 
         echo "</select>"; 
        echo "</div>"; 
        echo "<div class=\"col-xl-3\">"; 
         echo "<form action=\"\" method=\"POST\">"; 
         echo "<input class=\"btn btn-primary btn-sm \" type=\"submit\" name=\"find\" value=\"Submit\">"; 

         echo "</select>"; 
        echo "</div>"; 


       echo "</div>"; 
       echo "<div class=\"row tabela\" style=\"overflow: scroll !important\">";   
       echo "<table class=\"table table-bordered table-md\">"; 
       echo "<thead>"; 
        echo "<tr>"; 
         echo "<th>Imię Nazwisko</th>"; 
         echo "<th>Data</th>"; 
         echo "<th>Godzina</th>"; 
         echo "<th>Wej/wyj</th>";    
        echo "</tr>"; 
       echo "</thead>"; 
       echo "<tbody>"; 
       if(isset($_POST['find'])){ 

        $second_option = $_POST['nazwa1']; 
        echo "<div class=\"alert alert-success\" role=\"alert\">"; 
         echo "<a href=\"#\" class=\"alert-link\">".$second_option."</a>"; 
         echo "</div>"; 
        if($second_option == "Pracownik"){ 
         $query = "SELECT * FROM vDane "; 
         $result = mysqli_query($link, $query); 
         $row = mysqli_fetch_array($result); 

        } 
        if($second_option != "Pracownik"){ 
         $query = "SELECT * FROM vDane WHERE Nazwa = $second_option"; 
         $result = mysqli_query($link, $query); 
         $row = mysqli_fetch_array($result);   
        } 

         foreach($row as $row){ 
          echo "<tr>"; 
          echo "<th scope=\"row\">".$row['Nazwa']."</th>"; 
          echo "<td>".$row['Date']."</td>"; 
          echo "<td>".$row['Time']."</td>"; 
          echo "<td>".$row['Scan_ID']."</td>"; 
          echo "</tr>";  
         } 
        echo "</tbody>"; 
        echo "</table>"; 
        echo "</form>"; 



        } 
       mysqli_close($link); 

       ?> 

回答

0

嘗試在表名稱周圍放置方括號或反引號。

$query = "SELECT [Distinct Nazwa] FROM vDane "; 
    $query = "SELECT `Distinct Nazwa` FROM vDane "; 

它看起來像它試圖選擇「獨特」作爲你的表,而不是「獨特Nazwa」。根據Stack Overflow的一些問題,如果這是問題,上面的一個應該解決它。

+0

但它不是我的droplist中的問題我有數據庫中的數據,但是當我選擇一個它不顯示在表中。 – Komin

+0

它看起來像不會去第二個,如果它檢查$ second_option,但我現在不爲什麼它看起來不錯,我爲什麼 – Komin

+0

嘗試採取這一點,並把它放在選擇語句上方(右下方div class ='col-xl-3 ') echo「

」; 在我看來,它不會將select語句計算爲表單的一部分,因此它不會將其設置爲$ second_option。 – Rhea