Jump to content

Ever have a stupid moment?


Recommended Posts

$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.  :facepalm: 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?

Link to comment
Share on other sites

You might want to look into BETWEEN...




Even better! :D 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.)

Link to comment
Share on other sites



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.

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

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

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.