interpim Posted July 28, 2008 Share Posted July 28, 2008 Hi all, I have a form which has a bunch of drop down boxes to select from.... these submit to a results page which runs a query into a database I have. The problem I am having is I have a field called min_level which is an integer, and the form lets teh user select between levels to search for... so for instance, my user wants to find something with a min_level between 5 and 15 I want only the items which have a number between that to show up in the query. The problem is, I am getting all results as long as the query goes from 0 to the max allowable amount, when I adjust the settings I am getting back odd results, as in nothing showing up, or only certain ones. the script I have basically goes like this $sql = "Select * From items where career = '$career'"; if($min_lvl != ''){ $sql = $sql . " and min_level >= $min_lvl"; } if($max_lvl != ''){ $sql = $sql . " and =< $max_lvl"; } The reason I am using the statements is to give the user the option of using more or less search features for an item database I am building for an online video game. If anyone could square me away I would appreciate it Link to comment https://forums.phpfreaks.com/topic/117043-query-not-working/ Share on other sites More sharing options...
jake2891 Posted July 28, 2008 Share Posted July 28, 2008 $sql = "Select * From items where career = '$career'"; if($min_lvl != ''){ $sql .= " and min_level >= $min_lvl"; } if($max_lvl != ''){ $sql .= "and max_level <= $max_lvl"; } Link to comment https://forums.phpfreaks.com/topic/117043-query-not-working/#findComment-602038 Share on other sites More sharing options...
jake2891 Posted July 28, 2008 Share Posted July 28, 2008 Also the $career shudn't be in single quotes or else it will be read as a string and not its value. rather try '.$career.' Link to comment https://forums.phpfreaks.com/topic/117043-query-not-working/#findComment-602039 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.