<?php require_once "functions.php"; $car_list = getCarData(); ?> <table border= 1> <tr> <th>id</th> <th>user_id</th> <th>auto nr märk</th> <th>auto värv</th> </tr> <?php //iga massiivis oleva elemendi kohta //count($car_list) - massiivi pikkus for ($i = 0; $i < count($car_list); $i++) { //$i = $i + 1 == $i =+ 1 ==o $i++ echo "<tr>"; echo "<td>" . $car_list[$i]->id . "</td>"; echo "<td>" . $car_list[$i]->user_id . "</td>"; echo "<td>" . $car_list[$i]->number_plate . "</td>"; echo "<td>" . $car_list[$i]->color . "</td>"; echo "</td>"; } ?> </table>
<?php require_once "functions.php"; //kas kustutame //?delete=vastav id mida kustutada on aadressireal if (isset($_GET["delete"])) { echo "kustutame id " . $_GET["delete"]; //käivitan funktsiooni,saadan kaasa id deleteCar($_GET["delete"]); } //salvestan andmebaasi if (isset($_POST["save"])) { updateCar($_POST["id"], $_POST["plate_number"], $_POST["color"]); } //käivitan funktsiooni $array_of_cars = getCarData(); //trükin välja esimese auto //echo $array_of_cars[0]->id." ".$array_of_cars[0]->plate; ?> <h2>Tabel</h2> <table> <tr> <th>id</th> <th>Kasutaja id</th> <th>numbrimärk</th> <th>Värv</th> <th>Kustuta</th> <th>Redigeeri</th> </tr> <?php
<?php require_once "functions.php"; //kas kustutame, ?delete = vastav id mida kustutada on aadressireal if (isset($_GET["delete"])) { echo "Kustutame id" . $_GET["delete"]; //käivitan funktsiooni, saadan kaasa id deleteCar($_GET["delete"]); } //salvestan andmebaasi if (isset($_POST["save"])) { updateCar($_POST["id"], $_POST["plate_number"], $_POST["color"]); } //käivitan funktsiooni $car_array = getCarData(); //trükin välja esimese auto //echo $car_array[0]->id." ".$car_array[0]->plate; ?> <h2>Tabel</h2> <table border="1"> <tr> <th>Id</th> <th>User id</th> <th>Numbrimärk</th> <th>Värv</th> <th>X</th> <th>Edit</th> </tr> <?php
<?php require_once "functions.php"; //kas kustutame if (isset($_GET["delete"])) { echo "Kustutame id" . " " . $_GET["delete"]; // käivitan funktsiooni, saadan kaasa id deleteCar($_GET["delete"]); } //salvestan ab'i if (isset($_POST["Save"])) { updateCar($_POST["id"], $_POST["number_plate"], $_POST["color"]); } $array = getCarData(); ?> <h2>Tabel</h2> <table border=1> <tr> <th>ID</th> <th>User ID</th> <th>Numbrimärk</th> <th>Värv</th> <th>Kustuta</th> <th>Muuda</th> </tr> <?php for ($i = 0; $i < count($array); $i++) { //kasutaja tahab muuta if (isset($_GET["edit"]) && $array[$i]->id == $_GET["edit"]) { echo "<tr>";
$stmt->bind_result($id, $user_id, $number_plate, $color); $stmt->execute(); $array = array(); while ($stmt->fetch()) { $car = new StdClass(); $car->id = $id; $car->number_plate = $number_plate; $car->user_id = $user_id; $car->color = $color; array_push($array, $car); //echo "<pre>"; //var_dump($array); //echo "</pre>"; } $stmt->close(); $mysqli->close(); return $array; } function deleteCar($id_to_be_deleted) { $mysqli = new mysqli($GLOBALS["servername"], $GLOBALS["server_username"], $GLOBALS["server_password"], $GLOBALS["database"]); $stmt = $mysqli->prepare("UPDATE car_plates SET deleted=NOW() WHERE id=?"); $stmt->bind_param("i", $id_to_be_deleted); if ($stmt->execute()) { header("Location: table.php"); } $stmt->close(); $mysqli->close(); } getCarData();