I'm trying to limit the number of rows that the page shows according to the users selection from a drop down(think like a store page "show number of items per page")
At the moment I'm using php to call MySql and then echo out my results. I know that php cant do anything after the page loads. The next thing that comes to mind is java script. However I have no experience with java script, I'm fair normal with java.
What are other options that you would suggest?
note: I want to limit my while loop not the mysql result.
Here is my code as it stands now:
<form name="input" action="EditPartyP.php" method="post">
<tr>
<td>Party ID</td><td>Party Name</td>
<td>Start Date</td><td>End Date</td><td>Sales</td><td>VIEW:
The drop down selection options that are being offered.
<select>
<option value="10">10</option>
<option value="20">20</option>
<option value="40">40</option>
<option value="80">80</option>
</select>
</td>
The results from the query being displayed, I under stand that I will have to change this because the php is done when the user sees the output html.
<?php
$ID = $_SESSION['ID'];
$result = PartyData::PartyLookupByID($_SESSION['ID'], "DESC");
This loop now just runs until the result runs out of data. I need to make it stop when the users number is reached as well.
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo '<form name="input" action="EditPartyP.php" method="post">';
echo "<td>" . $row['PartyID'] . "</td>";
echo "<td>" . $row['PartyName'] . "</td>";
echo "<td>" . $row['sDate'] . "</td>";
echo "<td>" . $row['eDate'] . "</td>";
echo "<td>" . $row['PartyOrderTotal'] . " </td>";
echo '<input type="hidden" value=" ' . $row['PartyID'] . '" name="PartyID">';
echo "<td>" . '<button type="submit" value="Edit" name="Action">Edit</button>' . "</td>";
echo '</form>';
echo "</tr>";
}
?>
</table>
Thank you for reading and a comment helps more than a down vote.
You might want to look into https://datatables.net if you want features such as per page row diaplay or so called pagination.
Based on the selected page (via a $_GET['var'] and the users choice of number of records per page, you have to adjust your query with the limit statement.
SELECT * FROM table LIMIT 10, 50
Would start at the 10th record and will select 50 records max.
You can use SQL Limit command to retrieve specific number of data.
SELECT column_name(s) FROM table_name LIMIT number;