Jump to content

Recommended Posts

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:
$honor
and 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 :)
Link to comment
https://forums.phpfreaks.com/topic/3744-mysql-query/
Share on other sites

$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.
Link to comment
https://forums.phpfreaks.com/topic/3744-mysql-query/#findComment-12986
Share on other sites

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!
Link to comment
https://forums.phpfreaks.com/topic/3744-mysql-query/#findComment-12988
Share on other sites

[!--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!
Link to comment
https://forums.phpfreaks.com/topic/3744-mysql-query/#findComment-12997
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.