TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-02-2009, 10:04 PM   #1 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default SQL code...if NOT....

Ok, is there any way to make this query better? It seems like I should be able to somehow use less "AND"...



Code:
SELECT * FROM users WHERE user_id != '5' AND user_id != '6' AND user_id != '9' AND user_id != '3';
allworknoplay is offline  
Reply With Quote
Old 04-02-2009, 10:50 PM   #2 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

First, why are you wrapping integers in quotes? Second, and more to the point, to use less (no!) ANDs you could use …WHERE user_id NOT IN (5, 6, 9, 3)
Salathe is offline  
Reply With Quote
Old 04-02-2009, 10:56 PM   #3 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Salathe View Post
First, why are you wrapping integers in quotes? Second, and more to the point, to use less (no!) ANDs you could use …WHERE user_id NOT IN (5, 6, 9, 3)
Thank you!!

Yes I suppose using quotes turns the numbers into strings right?
Or is that just a PHP thing?
allworknoplay is offline  
Reply With Quote
Old 04-02-2009, 11:08 PM   #4 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Yes, it's just more work for the MySQL engine to do as I assume your user_id values are integers.
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
allworknoplay (04-02-2009)
Old 04-02-2009, 11:16 PM   #5 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Salathe View Post
Yes, it's just more work for the MySQL engine to do as I assume your user_id values are integers.
thanks, yes they are of "INT" value....

I will have to keep this in mind...

allworknoplay is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Injection and mysql_real_escape_string Durux General 61 01-29-2013 12:20 PM
Rating system sql code Orc General 23 01-29-2013 11:53 AM
Tips to Improve Your Coding and Projects Village Idiot Tips & Tricks 45 12-03-2012 07:46 AM
Writing Clean Code Village Idiot Tips & Tricks 10 06-25-2012 12:35 PM
SQL injections protection Rendair Tips & Tricks 23 12-11-2007 03:59 PM


All times are GMT. The time now is 08:03 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design