Коментарии

Автор:
echo "<th><a href='?sort=addressLine2'>Address 2</a></th>";
            echo "<th><a href='?sort=state'>State</a></th>";
            echo "<th><a href='?sort=country'>Country</a></th>";
            echo "<th><a href='?sort=postalCode'>Postal Code</a></th>";
            echo "<th><a href='?sort=territory'>Territory</a></th>";
            ?>
            <th></th>
          </tr>
        </thead>
        <tbody>
          <?php
         
foreach ($result as $row) {
           
// Iteration über alle Datensätze -> Ergebnis ist ein 1-dimensionales assoziatives Array
            // print_r($result); // Ausgabe des Arrays zu Testzwecken
           
echo "<tr>";
           
// Werte in einer Table-row ausgeben
           
echo "<td><input type='checkbox' name='del[]' value='" $row['officeCode'] . "'></td>";
            echo 
"<td>" $row['officeCode'] . "</td>";
            echo 
"<td>" $row['city'] . "</td>";
            echo 
"<td>" $row['phone'] . "</td>";
            echo 
"<td>" $row['addressLine1'] . "</td>";
            echo 
"<td>" $row['addressLine2'] . "</td>";
            echo 
"<td>" $row['state'] . "</td>";
            echo 
"<td>" $row['country'] . "</td>";
            echo 
"<td>" $row['postalCode'] . "</td>";
            echo 
"<td>" $row['territory'] . "</td>";
            echo 
"</tr>";
          }
         
?>
        </tbody>
      </table>
      <button type="submit">Delete Selected</button>
    </form>
  </div>
</body>

</html>
2025-03-28 13:35:10
http://php5.kiev.ua/manual/ru/language.variables.html
Автор:
<?php
session_start
();

// Datenbankverbindung etablieren
$servername "mysql";
$username "root";
$password "htlkrems";
try {
 
// Instanz des PDO Objektes erzeugen
 
$conn = new PDO("mysql:host=$servername;dbname=classicmodels"$username$password);
 
// PDO Error Mode auf Exception setzen
 
$conn->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
 
//echo "Connected successfully"; // Ausgabe wenn DB-Verbindung ok
} catch (PDOException $e) {
 
// Ausgabe der Fehlermeldung falls DB-Verbindung fehlgeschlagen
 
echo "Connection failed: " $e->getMessage();
}

if (isset(
$_GET['del'])) {

  if (isset(
$_GET['del']) && is_array($_GET['del'])) {

   
$deleteIds $_GET['del'];

    foreach (
$deleteIds as $ele) {

     
$conn->query("SET FOREIGN_KEY_CHECKS = 0");
     
$conn->query("DELETE FROM offices WHERE officeCode LIKE '$ele'");
    }
  }
}

if (!isset(
$_SESSION['search'])) {
 
$_SESSION['search'] = "";
}

if (isset(
$_GET["search"])) {
 
$_SESSION['search'] = $_GET["search"];
}

if (!isset(
$_SESSION['sort'])) {
 
$_SESSION['sort'] = "officeCode";
}

if (isset(
$_GET['sort'])) {
 
$_SESSION['sort'] = $_GET['sort'];
}

$search $_SESSION['search'];
if (isset(
$_GET['lett'])) {
 
$lookfor $_GET['lett'];
 
$search '';
 
$_SESSION['search'] = '';
} else {
 
$lookfor $search;
}
$sort $_SESSION['sort'];

$stmt $conn->query("SELECT * FROM offices WHERE city LIKE '$lookfor%' ORDER BY $sort");   // SQL Query ausführen
$result $stmt->fetchAll(PDO::FETCH_ASSOC);      // alle Daten mit fetchAll fetchen -> Ergebnis ist ein 2-dimensionales Array

?>

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Products</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
</head>

<body>
  <div class="container">
    <!-- STEP 1: Ausgabe des Array -->
    <?php
   
// echo "<pre>"; print_r($result); echo "</pre>"; 
   
?>

    <!-- STEP 2: Ausgabe in einer HTML-Tabelle -->
    <h1>Products</h1>
    <table>
      <thead>
        <tr>
          <?php
         
for ($i 0$i 26$i++) {
            echo 
"<th><a href='?lett=" chr(65 $i) . "'>" chr(65 $i) . "</a></th>";
          }
         
?>
        </tr>
      </thead>
    </table>
    <form action="offices.php" method="GET">
      <?php
     
echo "<input type='text' name='search' value='" $_SESSION['search'] . "'>";
     
?>
      <input type="submit">
    </form>
    <form action="offices.php" method="GET">
      <table class="table">
        <thead>
          <tr>
            <th></th>
            <?php
           
echo "<th><a href='?sort=officeCode'>Office Code</a></th>";
            echo 
"<th><a href='?sort=city'>City</a></th>";
            echo 
"<th><a href='?sort=phone'>Phone</a></th>";
            echo 
"<th><a href='?sort=addressLine1'>Address 1</a></th>";
            echo 
"<th><a href='?sort=addressLine2'>Address 2</a></th>";
            echo 
"<th><a href='?sort=state'>State</a></th>";
            echo 
"<th><a href='?sort=country'>Country</a></th>";
            echo 
"<th><a href='?sort=postalCode'>Postal Code</a></th>";
            echo 
"<th><a href='?sort=territory'>Territory</a></th>";
           
?>
            <th></th>
          </tr>
        </thead>
        <tbody>
          <?php
         
foreach ($result as $row) {
           
// Iteration über alle Datensätze -> Ergebnis ist ein 1-dimensionales assoziatives Array
            // print_r($result); // Ausgabe des Arrays zu Testzwecken
           
echo "<tr>";
           
// Werte in einer Table-row ausgeben
           
echo "<td><input type='checkbox' name='del[]' value='" $row['officeCode'] . "'></td>";
            echo 
"<td>" $row['officeCode'] . "</td>";
            echo 
"<td>" $row['city'] . "</td>";
            echo 
"<td>" $row['phone'] . "</td>";
            echo 
"<td>" $row['addressLine1'] . "</td>";
2025-03-28 13:35:56
http://php5.kiev.ua/manual/ru/language.variables.html

    Поддержать сайт на родительском проекте КГБ