Page 1 of 1

part of query is being ignored

Posted: Mon Jun 29, 2009 11:58 am
by nite4000
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

Code: Select all

<?php
                
                $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());      
            while($info = mysql_fetch_array($q, MYSQL_ASSOC)) {
echo'<tr><td><input type=checkbox name=del[] id=del value='.$info[id].'>
</td><td><img src="../images/email.png"></td>
              <td align="left"><a href="surf_mail.php?id=' . $info['id'] . '">admin@blah.com</a></td>
              <td align="left">'.$info['subject'].'</td>
              <td>'.date("n-d-y",strtotime($info['sent'])).'</td></tr>';
            }
                
        ?>

Re: part of query is being ignored

Posted: Mon Jun 29, 2009 12:18 pm
by Eric!
Are you getting an error? I'm not great at sql, but how about adding a space between blah.com'and ?

Code: Select all

              $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());

Re: part of query is being ignored

Posted: Mon Jun 29, 2009 12:19 pm
by nite4000
no no error just not getting rows that have the status of 4 and admin@blah.com but the other part works not sure what caused it to stop working.

Re: part of query is being ignored

Posted: Mon Jun 29, 2009 12:37 pm
by Eric!
Did you see I corrected a syntax problem with your query?

Re: part of query is being ignored

Posted: Mon Jun 29, 2009 12:41 pm
by nite4000
yeah i saw but still not working like it should. its getting the first part where email is ses_name and status=1 but not the rest.

I added info to my profile if you wish to contact me

Re: part of query is being ignored

Posted: Mon Jun 29, 2009 1:07 pm
by VladSun
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.

Re: part of query is being ignored

Posted: Mon Jun 29, 2009 1:10 pm
by nite4000
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.

Re: part of query is being ignored

Posted: Mon Jun 29, 2009 1:15 pm
by VladSun
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]

Re: part of query is being ignored

Posted: Mon Jun 29, 2009 1:23 pm
by nite4000
Thanks but didnt work. I think i am gonna just make another page to have it show the status=4 stuff may be alot easier.

Thanks

Re: part of query is being ignored

Posted: Mon Jun 29, 2009 2:16 pm
by nite4000
putting it on another page didnt work something is stopping it from working. You have any other suggestions?