joecooper Posted February 28, 2006 Share Posted February 28, 2006 i have this:$sql = "SELECT * FROM aaform WHERE map1 IN ('$s_map1', '$s_map2', '$s_map3') OR map2 IN ('$s_map1', '$s_map2', '$s_map3') OR map3 IN ('$s_map1', '$s_map2', '$s_map3') ORDER BY honor ASC";theres nothing wrong with that, it allworks.i have this string:$honorand it needs to equal numbers ($from $to) which could be from:25 to:84 its what ever the user enters.and i need it to only display the results where honor is between those numbers...ive tryed this:$sql = "SELECT * FROM aaform WHERE map1 IN ('$s_map1', '$s_map2', '$s_map3') OR map2 IN ('$s_map1', '$s_map2', '$s_map3') OR map3 IN ('$s_map1', '$s_map2', '$s_map3') AND honor= '>$to < $from' ORDER BY honor ASC";but that dont work...im confused as to how i can make it do this.any help would be good.if its not clear enough, ill try and make it make more sence :) Quote Link to comment https://forums.phpfreaks.com/topic/3744-mysql-query/ Share on other sites More sharing options...
ToonMariner Posted February 28, 2006 Share Posted February 28, 2006 $sql = "SELECT * FROM aaform WHERE (map1 IN ('$s_map1', '$s_map2', '$s_map3') OR map2 IN ('$s_map1', '$s_map2', '$s_map3') OR map3 IN ('$s_map1', '$s_map2', '$s_map3')) AND honor BETWEEN ('$to' , '$from') ORDER BY honor ASC";I think anyway - long time since i used between. have a look around for it in the mysql manual you should find it somewhere. Quote Link to comment https://forums.phpfreaks.com/topic/3744-mysql-query/#findComment-12986 Share on other sites More sharing options...
obsidian Posted February 28, 2006 Share Posted February 28, 2006 for this type of query, it's all in using parenthesis to define your order of precidence. try this and see if it helps:[code]SELECT * FROM aaform WHERE (map1 IN ('$s_map1', '$s_map2', '$s_map3') OR map2 IN ('$s_map1', '$s_map2', '$s_map3') OR map3 IN ('$s_map1', '$s_map2', '$s_map3')) AND (honor > ($from - 1) AND honor < ($to + 1)) ORDER BY honor ASC[/code]or, you could just use BETWEEN:[code]SELECT * FROM aaform WHERE (map1 IN ('$s_map1', '$s_map2', '$s_map3') OR map2 IN ('$s_map1', '$s_map2', '$s_map3') OR map3 IN ('$s_map1', '$s_map2', '$s_map3')) AND (honor BETWEEN $to AND $from) ORDER BY honor ASC[/code]notice i used ($from - 1) and ($to + 1) to INCLUDE the to and from numbers. if you don't want those numbers included, just remove the operation.hope this helps! Quote Link to comment https://forums.phpfreaks.com/topic/3744-mysql-query/#findComment-12988 Share on other sites More sharing options...
joecooper Posted February 28, 2006 Author Share Posted February 28, 2006 thanks! the +1 and -1 things are a bonus, was going to do that :D thanks ever so much! Quote Link to comment https://forums.phpfreaks.com/topic/3744-mysql-query/#findComment-12990 Share on other sites More sharing options...
obsidian Posted February 28, 2006 Share Posted February 28, 2006 [!--quoteo(post=350198:date=Feb 28 2006, 08:31 AM:name=joecooper)--][div class=\'quotetop\']QUOTE(joecooper @ Feb 28 2006, 08:31 AM) [snapback]350198[/snapback][/div][div class=\'quotemain\'][!--quotec--]thanks! the +1 and -1 things are a bonus, was going to do that :D thanks ever so much![/quote]the BETWEEN command is also inclusive, so if you want a little cleaner SQL code, that's probably the way to go.good luck! Quote Link to comment https://forums.phpfreaks.com/topic/3744-mysql-query/#findComment-12997 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.