0
How can i get paginated results from this code ?
<?php include 'connection.php'; session_start(); $sql = "SELECT origin,destination,departure,arrival,craftoperator,date,returndte,operatorlogo,Price FROM test WHERE origin = '".$_REQUEST['origin']."' AND destination = '".$_REQUEST['destination']."'AND date = '".$_REQUEST['departure']."' OR returndte = '".$_REQUEST['return']."' "; $result = $conn->query($sql); while($row = mysqli_fetch_assoc($result)) { $output[]=$row; } print(json_encode($output)); ?>
3 Respuestas
+ 1
you can set an OFFSET and a LIMIT in your sql: it will retrieve the number of results defined by the limit starting from the offset.
OFFSET 10 LIMIT 20
will get you ten results (if available in your db) starting from the tenth. if you send the page number 2 and you set the offset = pagenumber *10 you'll get the next 10 results after the 20th (using the same limit).
use pdo or mysqli prepared statements for better security, filter, validate and escape any parameter before you bind it to a query to avoid sql injection
+ 1
online there is more than i can possibly know.
here is a good starting point:
check Adam Khoury's youtube channel https://m.youtube.com/playlist?list=PLlkGN-8wjPHV41Y12LFD8uttbAd1d_ohe
or w3schools
0
I would love your help can we get in touch