Jump to content

SELECT problems


luke.browning

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/194334-select-problems/
Share on other sites

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}%'
);

Link to comment
https://forums.phpfreaks.com/topic/194334-select-problems/#findComment-1022814
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.