PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have some code here and it was working fine at one point not sure why it stopped. but its ignoring part of the query after OR and i need all of it to be shown
if maybe there is another way to code the query that would help or tell me what to google for and i will figure it out on my own
Here is the code
$q=mysql_query("Select * from support where email='" . $_SESSION['sess_name'] . "' and status='1' OR email='admin@blah.com' and status='4' and id= '$usrid' ORDER BY SENT DESC ")or die(mysql_error());
Could you please explain what this:
[sql]here email='" . $_SESSION['sess_name'] . "' AND STATUS='1' OR email='admin@blah.com'AND STATUS='4' AND id= '$usrid'[/sql]
describes in real world?
I'm almost sure you have a precedence issue here.
There are 10 types of people in this world, those who understand binary and those who don't
VladSun wrote:Could you please explain what this:
[sql]here email='" . $_SESSION['sess_name'] . "' AND STATUS='1' OR email='admin@blah.com'AND STATUS='4' AND id= '$usrid'[/sql]
describes in real world?
I'm almost sure you have a precedence issue here.
yeah i will explain it.
This here email='" . $_SESSION['sess_name'] . "' is the email thats logged in with and status='1' is the status of emails the other part after OR is where i send a mass mail to them via saved to db in the same table but is given a default email and a different status which is 4 since i sent it to them and this id= '$usrid' is the id of the record of the user
hope that helps. it did work but not sure why it stopped.
Obviously, STATUS is a MySQL keyword so escape it like this:
[sql]WHERE email='" . $_SESSION['sess_name'] . "' AND `status`='1' OR email='admin@blah.com' AND `status`='4' AND id= '$usrid'[/sql]
Also try using brackets t express the right precedence:
[sql]WHERE ( (email='" . $_SESSION['sess_name'] . "' AND `status`='1') OR (email='admin@blah.com' AND `status`='4') ) AND id= '$usrid'[/sql]
There are 10 types of people in this world, those who understand binary and those who don't