Issue
I'm having what may be the dumbest issue.
I'm using phpmyadmin and when I query a table using OR
it does not return all values.
This is the query that is not returning all values:
SELECT * FROM ecrdatabase.ecrtable m WHERE m.ecrChangeOwner = '$partialOwner' OR m.ecrInitByName = '$partialOwner'
.
Here, $partialOwner
is passed from $_GET['user']
.
Some of the rows are returned - just not all of them. I have a php page that queries the database and I have tried running the query directly on the database through phpmyadmin using query:
SELECT * FROM ecrtable WHERE ecrChangeOwner = 'ecunningham' OR ecrInitByName = 'ecunningham'
.
Both results from the the direct query and php page return the same number of rows.
I have also tried:
SELECT * FROM ecrtable WHERE (ecrChangeOwner = 'ecunningham' OR ecrInitByName = 'ecunningham')
.
What am I missing? I have more complex queries that run fine. Please tell me I'm just missing something stupid...
Solution
You really should be using prepared statements here, first of all. You are wide open to injection attacks.
Second, how do you know that this query does not return all the rows? What queries have you done to verify that this one is wrong?
If you run a union what do you get:
SELECT * FROM ecrtable WHERE ecrChangeOwner = 'ecunningham'
UNION ALL
SELECT * FROM ecrtable WHERE ecrInitByName = 'ecunningham')
Answered By - mikeb
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.