如何在php/mysql中制作价格范围系统


How to make price range system in php/mysql?

我想创建一个价格范围系统,使用 php/mysql 作为product table

示例这是表

这是产品表:

id name       price 
1  pen          25
2  pencil       75
3  rubber       100
4  bag         250
5  bike        800

这就是我想要实现的目标

if we select price 
from 0 - 30 (1) Only product of that range should display 
if we select price 
from 100 - 250 (1) Only product of that range should display 
and so on...

我怎样才能用php和mysql来实现这一点?
任何提示,指导都会有所帮助。
对于 php 新手,我应该如何承担这项任务。

使用 MySQL between :-

select * from product where price between 0 and 30 

select * from product where price between 100 and 250 

使用 BETWEEN

SELECT *
FROM product table
WHERE price 
BETWEEN
0 AND 30;// pass your range here

你需要使用 Mysql 的 Between 关键字。介于关键字之间检查范围之间的值。使用此查询。根据需要更改值。

假设您的下限为 $price1,上限为 price2

Select * from product where price between $price1 and $price2

在这里,我解释了价格游侠如何在选择查询中工作

查询将是这样的

Select * from product where price between $lower and $higher;

$lower是价格游侠的最小值和

$higher是价格游侠的更高价值