php_b34st Posted October 22, 2006 Share Posted October 22, 2006 Hi, I have a table similar to the following:|col1|col2|_ _ _ _ _ _|1 |300|_`_`_`_ _|2 |400|_ _ _ _ _ _|3 |500|_ _ _ _ _ _|4 |600|_ _ _ _ _ _|5 |700|I would like it so that when a user enters a number for col 2 I can select the corresponding number in col 1 which is closest but not higher. for example if a user inputs 450 the db would output 2 becuse 400 is closest to it without being higher. Any ideas? Quote Link to comment Share on other sites More sharing options...
AndyB Posted October 22, 2006 Share Posted October 22, 2006 SELECT col1 from tablename WHERE col2<'$user_input_value' ORDER by col2 DESC limit 1 Quote Link to comment Share on other sites More sharing options...
php_b34st Posted October 22, 2006 Author Share Posted October 22, 2006 wow n theres me trying to look for a complex way trying to use max() and everything. Thank you Andy Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.