I have simple code in PHP and MySQL and Im trying to change LIMIT in MySQL query on click.
I found following method on stackoverflow but nnot working.
I want when someone click on the button LIMIT will be changed from 0 and 11 to 11 and 22. So I make if statement when $_POST exists to variable which holds values 0 and 11 will be added 11 to both. But my code dont working.
My code:
if ( $_POST ) {
$limit1 += 11;
$limit2 += 11;
} else {
$limit1 = 0;
$limit2 = 11;
}
?>
<h2>DOKUMENTY</h2>
<div class="ciara"></div>
<ul class="doc-list">
<?php
if ($db->connect_error) {
die("Not connected: " .
$db->connect_error);
}
$sql = "SELECT * FROM (
SELECT * FROM upload
ORDER BY id DESC
LIMIT $limit1, $limit2
) sub
ORDER BY id DESC";
$result = $db->query($sql);
if ($result->num_rows) {
while ($row = $result->fetch_assoc()) {
echo '<li class="'.($row['id'] % 2 == 0 ? 'light' : 'dark').'"><a href="'. $row["location"] .'">' . $row["headline"] . "</a></li>";
}
}
?>
</ul>
<form method="post">
<input type="hidden" value="g">
<input type="submit" value="Next">
</form>