Am having 500 records in table am having pagination as showing 100 per page or 200 per page. Am having filter dropdown for category. At first when I select category dropdown for filtering its showing correct data am showing 100 entries for each page by default. I am having 200 records of a particular category so I selected 200 entries then selected category gone from dropdown and its showing all records. I have used two seperate forms for entries and category filter.
<div>
<?php
// put all your options into an array
$options = array(0 => 'Select Entries', 500 => 500, 1000 => 1000, 2000 => 2000, 3000=>3000);
?>
<form enctype="multipart/form-data" method="post" action="" style="padding-bottom:10px;" >
<select class="selectpicker" name="results" onchange="this.form.submit();">
<?php
// loop trough the elements
foreach($options as $value => $label) {
// test if the current value is the posted one...
$selected = (isset($_POST['results']) && intval($_POST['results']) === $value) ? ' selected="selected"' : '';
echo '<option value="'.$value.'"'.$selected.'>'.$label.'</option>';
}
?>
</select>
</form>
</div>
<div style="padding-left:200px;">
<button>Export</button>
</div>
<div style="padding-left:200px;">
<?php
// put all your options into an array
$filters = array(0 => 'Select based', 1 => 'Pending', 2 => 'Completed');
?>
<form enctype="multipart/form-data" method="post" action="" style="padding-bottom:10px;" >
<select class="selectpicker" name="filter_results" onchange="this.form.submit();">
<?php
// loop trough the elements
foreach($filters as $value => $label) {
// test if the current value is the posted one...
$selected = (isset($_POST['filter_results']) && intval($_POST['filter_results']) === $value) ? ' selected="selected"' : '';
echo '<option value="'.$value.'"'.$selected.'>'.$label.'</option>';
}
?>
</select>
</form>
</div>
$page_id = isset($_GET['page']) ? $_GET['page'] : false;
if(isset($_POST['results']))
{
$results_per_page = $_POST['results'];
}
else
{
$results_per_page = 500;
}
if(!empty($_POST["filter_results"])) {
$filters_1 = $_POST['filter_results'];
$query="SELECT * FROM video_data WHERE filter_results = $filters_1";
}
else
{
$query="SELECT * FROM video_data";
}
$select_categories=mysqli_query($connection,$query);
$number_of_categories = mysqli_num_rows($select_categories);
$number_of_pages = ceil($number_of_categories/$results_per_page);
// determine which page number visitor is currently on
if (!isset($_GET['page'])) {
$page = 1;
} else {
$page = $_GET['page'];
}
$this_page_first_result = ($page-1)*$results_per_page;
if(!empty($_POST["filter_results"])) {
$filters_1 = $_POST['filter_results'];
$sql='SELECT * FROM video_data WHERE filter_results ='. $filters_1.' ORDER BY id DESC LIMIT ' . $this_page_first_result . ',' . $results_per_page;
}
else
{
$sql='SELECT * FROM video_data ORDER BY id DESC LIMIT ' . $this_page_first_result . ',' . $results_per_page;
}