Reputation: 309
My title might seems unclear. I will describe what I want to do.Let's say the picture shown below is my index.php. If I click 0-100 in 'Select by price', it redirects me to another php file. The difference between this index.php and the '0-100' is just a mysql query that shows different products according to the price in the products box and same for all the others too. Now I realize that it is not a good way to do. And I tried to google my problem but as I am new in PHP i could not find the exact technological name to search in internet. Could you please help me how can I solve my problem or please share the link like my problem.
Upvotes: 0
Views: 74
Reputation: 763
You should use 'switch', very basic solution:
<a href="index.php?price_from=0&price_to=100">Click</a>
<?php
if(!isset($_GET['price_from']) && !isset($_GET['price_to']))
{
redirect to index or something
}
switch($_GET['price_from'].'-'.$_GET['price_to'])
{
case '0-100':
echo 'Your content';
break;
case '100-300':
echo 'Your content';
break;
case '300-500':
echo 'Your content';
break;
default:
load index or something
}
Upvotes: 1
Reputation: 6907
1. One way would be to use php get variables in the php file, and echo items if price lies between the variable value.
Your url would be something likeindex.php?low=0&high=100
.
This gives you two variables, the lower limit on price and the higher limit on price.
While echoing the product you can check for condition,
if($price>=$_GET['low'] && $price<=$_GET['high']){
//then only show the item.
}
2. Another way would be to use javascript or jquery.
Where you can iterate over items and hide them if they do not belong to selected range client side itself. Hence, the page will have to be reloaded if user changes the price ranges.
Upvotes: 1