homepage Welcome to WebmasterWorld Guest from 54.167.179.48
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Retrieving numbers within a certain range
pixeldiver

5+ Year Member



 
Msg#: 3977555 posted 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

5+ Year Member



 
Msg#: 3977555 posted 7:12 am on Aug 24, 2009 (gmt 0)

can you pls explain the question a bit more

Pico_Train

5+ Year Member



 
Msg#: 3977555 posted 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

5+ Year Member



 
Msg#: 3977555 posted 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

5+ Year Member



 
Msg#: 3977555 posted 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

5+ Year Member



 
Msg#: 3977555 posted 6:43 am on Aug 25, 2009 (gmt 0)

Thanks Nil111, I fixed it and it runs smoooth!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved