PugJr Posted October 11, 2009 Share Posted October 11, 2009 $query = "SELECT * FROM table WHERE object > '0' AND '25' > object"; I just realized I could do that with the ">" and "<". I used to do that except with 25 different queries with "=" instead. Ha ha. Man I feel stupid. This new way is several times faster and much easier to code. Have any of you people previously have experiences like mine where you coded something but did it an extremely stupid way? Quote Link to comment https://forums.phpfreaks.com/topic/177266-ever-have-a-stupid-moment/ Share on other sites More sharing options...
zq29 Posted October 11, 2009 Share Posted October 11, 2009 You might want to look into BETWEEN... SELECT * FROM `foo` WHERE `bar` BETWEEN 0 AND 24; Quote Link to comment https://forums.phpfreaks.com/topic/177266-ever-have-a-stupid-moment/#findComment-934647 Share on other sites More sharing options...
PugJr Posted October 11, 2009 Author Share Posted October 11, 2009 You might want to look into BETWEEN... SELECT * FROM `foo` WHERE `bar` BETWEEN 0 AND 24; Even better! I assume this will be faster for the computer as well, right? Hmm...I probably need to look at a MYSQL manual instead of a PHP one as that doesn't include that unless I missed it... (By the way, do you have a page that lists all the things you can do with a query as far as operators go and such.) Quote Link to comment https://forums.phpfreaks.com/topic/177266-ever-have-a-stupid-moment/#findComment-934650 Share on other sites More sharing options...
PugJr Posted October 11, 2009 Author Share Posted October 11, 2009 Between 1. (100 loops) 0.16122 2. (100 loops) 0.27198 3. (100 loops) 0.17759 4. ( 1000 loops) 1.86375 5. ( 1000 loops) 2.00561 For greater and less than signs. 1. (100 loops) 0.26809 2. (100 loops) 0.16846 3. (100 loops) 0.1873 4. (1000 loops) 1.84106 5. (1000 loops) 1.73132 For whatever reason, between is significantly slower than greater than and less than signs. EDIT: Oops! The greater than and less than sign one had less. I replace the wrong numbers with the new one. Now the numbers are nearly the same. So most likely it does just a tiny difference as those statistics can't always be reliable. Quote Link to comment https://forums.phpfreaks.com/topic/177266-ever-have-a-stupid-moment/#findComment-934655 Share on other sites More sharing options...
Daniel0 Posted October 11, 2009 Share Posted October 11, 2009 It's just a shortcut. It does exactly the same thing. It cannot check if it's less than something and greater than something else at the same time anyway. It's purely a convenience feature. Quote Link to comment https://forums.phpfreaks.com/topic/177266-ever-have-a-stupid-moment/#findComment-934986 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.