我编写了这段代码,点击“提交”按钮后,它不会显示包含数据的表格。我检查过nazwa1是否包含一些字符串,但它不会显示任何内容。我是PHP和HTML的新手,所以我不确定这是好的代码。我读了一些网站,我认为我的代码看起来不错。我到处寻找答案,但我一无所获。谢谢你的帮助。
<?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 :(得分:0)
尝试在表名周围加上方括号或反引号。
COPY FROM
在我看来,它试图选择“Distinct”作为你的桌子,而不是“Distinct Nazwa”。根据一些Stack Overflow问题,如果这是问题,上面的一个应该解决它。