hi i have set up a php based form submission method for sorting rows per page in a select drop down menu, it is working fine i get to sort the rows according to value selected, but my problem is when a value is selected for sort it doesn’t shows up in form selected field as whats currently selected.
what i mean to say is that when a value is selected in drop down menu for sorting rows it should show up as current in select-box as default value, and if nothing is selected then default row value should show up as current.
please see here here at the sorting method, it shows current(10) as default rows and when a value is selected it becomes as current on page reloads after querying database.
here is my html code for form field:
<form action="is-test.php" method="get">
<select name="rpp" onchange="this.form.submit()">
<option selected value="">show</option><!-- i want default & current selected value here -->
<option value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
</select>
</form>
and php code for this sorting is:
$rowsperpage = '';
if (isset($_GET['rpp'])&& is_numeric($_GET['rpp'])) {
$rowsperpage = (int) mysql_real_escape_string($_GET['rpp']);
}else{
$rowsperpage='5';
}
and mysql query for this is:
$sql2 = "SELECT * FROM $tablename ORDER BY $orderby $sortby LIMIT $rowsperpage OFFSET $offset";
please sugest me a way to set selected value as current value.
Thanks
In your
<option>tags, you should performed checking like this:So if you select
20, it will displayed as the current value of the<select>To make things simpler, just use
forloop like this: