Welcome to WebmasterWorld Guest from 22.214.171.124 , register , free tools , login , search , pro membership , help , library , announcements , recent posts , open posts Become a Pro Member
Retrieving numbers within a certain range pixeldiver
I have a form where users can submit an air quantity as a number. The database has rows such as id, air_quantity, product name etc.
What I am trying to do is when a user subitted the number, it should actually return values within a certain range which would be (id -1, and id +2).
So, the output would be 4 rows (one below, the closest search value, two rows above the search value).
What would be the easiest way to get such an output?
Any help would be great!
can you pls explain the question a bit more Pico_Train
$bottom = $_POST['air_quantity'] - 1 $top1 = $_POST['air_quantity'] + 1 $top2 = $_POST['air_quantity'] + 2
select * from table_name where air_quantity = $_POST['air_quantity'] or
air_quantity = $bottom or air_quantity = $top1 or air_quantity = $top2
Will that work?
Not pretty but it should do the trick.
Thanks, I tried this but it doesn't give me the results I wish.
The problem is, I have certain values such as 45, 55, 80 in the database and if someone puts in 46 it doesn't give me any results.
It should look for the closest matching and then look for the one below and the two upper values and return the 4 values. nil111
$usr_val = $_POST['num']; //number entered by user
$val_below = $usr_val-1;
$val_upper1 = $usr_val+1; $val_upper2 = $usr_val+2;
$query = "select * from table_name where column_name = '$usr_val' or column_name = '$val_below' or column_name = '$val_upper1' or column_name = '$val_upper2'";
run this query it should work.
Thanks Nil111, I fixed it and it runs smoooth!