How can i get paginated results from this code ? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
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)); ?>

16th May 2018, 12:44 AM
Wori Joseph Kasedde
Wori Joseph Kasedde - avatar
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
16th May 2018, 8:18 PM
seamiki
seamiki - avatar
+ 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
18th May 2018, 6:44 AM
seamiki
seamiki - avatar
0
I would love your help can we get in touch
17th May 2018, 1:57 PM
Wori Joseph Kasedde
Wori Joseph Kasedde - avatar