1 (edytowany przez kamil 18-04-2023 10:52:28)

Temat: Zadanie PHP+SQL (firma1>tabela: baza)

Zadanie PHP+SQL (baza.sql)

https://ti.dxe.pl/files2/baza.jpg


Baza do pobrania:
https://ti.dxe.pl/files2/baza.sql


Kod:

<?php
  if (isset($_POST["q"])) $q=(int)$_POST["q"]; else $q="rok";
  if (empty($q)) $q="rok";
?>
<form action="firma1.php" method="post">
  Rok: <input type="text" name="q" value="<?php echo $q; ?>">
  <input type="submit" value="Szukaj">
</form>
<hr>
<?php
  echo "<table border=1>";
  echo "<tr>";
  echo "<td bgcolor=yellow>`id`</td>";
  echo "<td bgcolor=yellow>`imie`</td>";
  echo "<td bgcolor=yellow>`nazwisko`</td>";
  echo "<td bgcolor=yellow>`stanowisko`</td>";
  echo "<td bgcolor=yellow>`rok`</td>";
  echo "</tr>";
  if ($_POST)
  {
    $co=mysqli_connect("localhost", "root", "", "firma1");
    $qu=mysqli_query($co, "SELECT * FROM baza WHERE rok=".$q.";");
    $i=0;
    while ($re=mysqli_fetch_array($qu))
    {
      if ($i%2==0) $b="#e3e7e6"; else $b="#ffffff";
      echo "<tr>";
      echo "<td bgcolor=".$b.">".($re["id"])."</td>";
      echo "<td bgcolor=".$b.">".($re["imie"])."</td>";
      echo "<td bgcolor=".$b.">".($re["nazwisko"])."</td>";
      echo "<td bgcolor=".$b.">".($re["stanowisko"])."</td>";
      echo "<td bgcolor=".$b.">".($re["rok"])."</td>";
      echo "</tr>";
      $i++;
    }
    mysqli_close($co);
  }
  else echo "<tr><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td></tr>";
  echo "</table>";
?>