Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
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.