Przejdź do treści

notatka.php

<?php
/*
 * Template Name: Notatki
 * description: >-
  Szablon dla strony notatki.
 */

 function get_notes($cupii){

    global $wpdb;
    $table_name = $wpdb->prefix . "notatki_ctt";
    $cupii_esc = esc_sql( $cupii );
    // TODO - dodać indeks na cupii
    $sql = "SELECT cupii, notatka, update_datetime  FROM {$table_name} WHERE cupii = '{$cupii_esc}' ORDER BY update_datetime DESC";
    $result = $wpdb->get_results( $sql );

    return $result;

}
?>

<h1>Notatki CTT</h1>
<form method="get">
    <label for="cupii">Numer Cupi:</label><br>
    <input type="number" name="cupii" placeholder="Podaj cupii aby odzyskać notatkę"  required/>
    <input type="submit" value="Szukaj" />
</form>

<table>
    <thead>
        <tr>
            <th>Cupii</th>
            <th>Data i godzina</th>
            <th>Notatka</th>
        </tr>
    </thead>
    <tbody>
        <?php
        if (isset($_GET['cupii'])) {
            $cupii = $_GET['cupii'];
            $notes = get_notes($cupii);
            foreach ($notes as $note) {
                echo "<tr>";
                echo "<td>{$note->cupii}</td>";
                echo "<td>{$note->update_datetime}</td>";
                echo "<td><pre>{$note->notatka}</pre></td>";
                echo "</tr>";
            }
        }
        ?>
    </tbody>
</table>

<style>
table, th, td {
  border: 1px solid black;
  border-collapse: collapse;
  padding: 5px;
}
</style>