Hello everyone: I have a problem on my site is working on them. I searched on a solution for 5 days and I can't find any result I needed it...
in short : I have list of car and I want to sort it by price descending and ascending use dropdown list and I used paging to split the record to 5 item in one page ..
when I choose for example a descending from drop down list it's show the result successful but when i go to the next page in paging the sort it's lost..
I trying use SESSION but isn't worked yet and still when I press on next page keep the sorting lost
I do modify update on the code after first replay but problem still exist:(
this is my html code:
<?php session_start();?>
<select name="price" id="price" class="css-dropdowns" tabindex="1" >
<option value="0">Price Ascending</option>
<option value="1">Ascending</option>
<option value="2">Descending</option>
</select>
this my code to paging:
$select_demo="select c.car_id, car_name,price,model_year,drive_traine,mile_age,exterior_color,interior_color,mbg,stocke_num,vin_num,video_url,image,body_style,cylinders_num,displacement,gearbox_speed,gearbox_type,brand_name
from car as c join car_body as cb
on c.car_id=cb.car_id
join engine as e
on c.car_id=e.car_id
join brand as b
on b.brand_id = c.brand_id
join transmission as t
on c.car_id=t.car_id";
if(!$demo_result=$db->query($select_demo))
{
die ($db->error);
}
$recored_count=$demo_result->num_rows;
$recored_limit=5;
if(isset($_GET['page']))
{
$page=$_GET['page'];//+1
}
else
{
$page=1;
}
$offset=($page-1)*$recored_limit;
$total_page=ceil($recored_count / $recored_limit );
?>
this is query to show data and sort:
$sql_paging="select c.car_id,car_name,price,model_year,drive_traine,mile_age,exterior_color,interior_color,mbg,stocke_num,vin_num,video_url,image,body_style,cylinders_num,displacement,gearbox_speed,gearbox_type,brand_name
from car as c join car_body as cb
on c.car_id = cb.car_id
join engine as e
on c.car_id = e.car_id
join brand as b
on b.brand_id = c.brand_id
join transmission as t
on c.car_id = t.car_id";
//to submit the dropdown list to get sort i want
if($_SERVER['REQUEST_METHOD']=='POST')
{
{
$_SESSION["price_filter"]=$_POST["price_filter"]; // call the ajax function to submit price drop down list
if (isset($_SESSION["price_filter"]) && !empty ($_SESSION["price_filter"]))
{
//query to show price 1 result
if ($_SESSION["price_filter"] == 1)
{
$sql_paging.=" order by price asc";
}
else if($_SESSION["price_filter"] == 2)
{
$sql_paging.=" order by price desc";
$_SESSION["price"]=($price ==2);
}
} //end of if filter
}//end of if request
$sql_paging.=" LIMIT $offset,$recored_limit";
if(!$paging_result=$db->query($sql_paging))
{
die ($db->error);
}
while($row=$paging_result->fetch_assoc())
{
##I don't paste all of codes it's just part of them for example ##
<code> echo "price".$row["price"]; }
this part of pagination with session to keep sort result when i go to next page
<!-- 1 st page-->
<li class=""> <a href="<?php echo $_SERVER["PHP_SELF"]."?page="."1"."&f=".$_SESSION["price_filter"]?>"><i class="fa fa-angle-left"></i></a></li>
<?php
for ($i=1; $i<=$total_page; $i++)
{?>
<li><a href="<?php echo $_SERVER["PHP_SELF"]."?page=".$i."&f=".$_SESSION["price_filter"]?>"><?php echo $i;?></a></li>
<?php } // end of for ?>
<!-- last page-->
<li><a href="<?php echo $_SERVER["PHP_SELF"]."?page=".$total_page ?>"><i class="fa fa-angle-right"></i></a></li>
finally this is first question and first try to question on this site can anybody help me to fixed this code ..
and sorry for bad English