<head> <title>Home | Flats</title> <link href="css/style.css" rel="stylesheet"> </head> <body> <h2>Les villes où nous sommes présents : </h2> <?php $results = (include 'lodging_search_app.php'); echo build_allCities($results['cities']); ?> <h2>Cherchez votre logement</h2> <form action="#" method="GET" id="flats-form"> <input type="text" name="flatsForm" placeholder="Votre appartement"> </form> <div id="results"> <?php echo build_allFlats($results['flats']); ?> </div> <script src="js/jquery.min.js"></script> <script src="js/main.js"></script> </body> </html>
} if (!empty($_GET['page'])) { $page = $_GET['page']; } else { $page = 1; } $pageSize = 2; $offset = ($page - 1) * $pageSize; if (strlen($flatsForm) < 3) { $statement = $pdo->prepare(sprintf('SELECT user.firstname, user.lastname, lodging.address, lodging.id FROM lodging JOIN user ON lodging.user_id = user.id ORDER BY id DESC LIMIT %1$u, %2$u ;', $offset, $pageSize)); $statement->execute(); } else { $statement = $pdo->prepare(sprintf('SELECT user.firstname, user.lastname, lodging.address, lodging.id FROM lodging JOIN user ON lodging.user_id = user.id WHERE city LIKE :research ORDER BY id DESC LIMIT %1$u, %2$u ;', $offset, $pageSize)); $statement->execute([':research' => '%' . $flatsForm . '%']); } $flats = $statement->fetchAll(); //************************************** DATA : pour le count ***************************************** $statementCount = $pdo->prepare(' SELECT COUNT(*) AS count FROM lodging; '); $statementCount->execute(); $flatsCount = $statementCount->fetchAll(); //*********************************************************************************************************** if (!empty($_GET)) { echo build_allFlats($flats); } else { return ["cities" => $cities, "flats" => $flats, "total" => $flatsCount]; }