I have a table of data, and I only want the first 5 entries to load, with a button at the bottom will load the entries 6 to 11. I've tried a few variations on adding a button but it's not showing the correct entries, the button at the moment will just show the same entries again. Here is the section of code;
if ($stmt = $mysqli->prepare("SELECT * FROM memo Where uid = ? ORDER BY id DESC LIMIT 5")) {
$stmt->bind_param("i", $uid2);
$stmt->execute();
$stmt->bind_result($id, $note, $uid3);
}
$output = array();
$out_id = array();
$out_note = array();
$i = 0;
if(isset($_POST['submit'])){
("SELECT * FROM memo Where uid = ? ORDER BY id DESC LIMIT 6, 11");
$stmt->bind_param("i", $uid2);
$stmt->execute();
$stmt->bind_result($id, $note, $uid3);
}
while ($stmt->fetch()) {
$out_note[$i] = $note;
echo $out_note[$i] . " <br>";
$i++;
}
$output = array(
$out_note,
$out_id
);
rsort($output);
$stmt->close();
$mysqli->close();
?>
<form action='' method='POST'>
<input type='submit' name='submit' />
</form>
You are talking about pagination. Limit is equal to fetch records from x record and fetch y number of records. The records from x to y become a page. For example page number 1 will have records from 0 to 5 and page number 2 will have records from 6 to 6+5. So you have number of records per page as a variable, start record as variable and page number as a variable. Based on that you can set the logic.