Welcome to WebmasterWorld Guest from 188.8.131.52 , register , login , search , subscribe , help , library , PubCon , announcements , recent posts , open posts Subscribe and Support WebmasterWorld
Retrieving numbers within a certain range pixeldiver msg:3977557 6:28 am on Aug 24, 2009 (gmt 0) 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!
nil111 msg:3977563 7:12 am on Aug 24, 2009 (gmt 0)
can you pls explain the question a bit more Pico_Train msg:3977565 7:13 am on Aug 24, 2009 (gmt 0)
$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.
pixeldiver msg:3978019 11:31 pm on Aug 24, 2009 (gmt 0)
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 msg:3978132 6:25 am on Aug 25, 2009 (gmt 0)
$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.
pixeldiver msg:3978141 6:43 am on Aug 25, 2009 (gmt 0)
Thanks Nil111, I fixed it and it runs smoooth!