luke.browning Posted March 6, 2010 Share Posted March 6, 2010 Hi all, I'm having a problem with the following statement: $sql = "SELECT DISTINCT Users.Username, Users.Firstname, Users.Surname, Settings.Title FROM Users, Settings WHERE Settings.Owner = Users.Username AND Users.Firstname LIKE '%{$query}%' OR Users.Surname LIKE '%{$query}%' OR Users.Username LIKE '%{$query}%' OR Settings.Title LIKE '%{$query}%'"; Basically its a little script thats just searching the database for the variable I pass in. The problem is, I have it running on my development system fine, returns the correct results. The problem is, when I upload it to my web server, the results returned are every possible combination of results as if the WHERE Settings.Owner = Users.Username is not being tested. I don't know if it makes much difference, but my development system runs mysql version 5.1.37 and my web server is running 5.0.89. Thanks for any help, Luke Quote Link to comment https://forums.phpfreaks.com/topic/194334-select-problems/ Share on other sites More sharing options...
straylight Posted March 7, 2010 Share Posted March 7, 2010 It might be precendence issues that are causing it. Try sticking those OR terms in brackets, like this: SELECT DISTINCT Users.Username, Users.Firstname, Users.Surname, Settings.Title FROM Users, Settings WHERE Settings.Owner = Users.Username AND ( Users.Firstname LIKE '%{$query}%' OR Users.Surname LIKE '%{$query}%' OR Users.Username LIKE '%{$query}%' OR Settings.Title LIKE '%{$query}%' ); Quote Link to comment https://forums.phpfreaks.com/topic/194334-select-problems/#findComment-1022814 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.