Page 1 of 1

how do i have multiple WHERE clauses???

Posted: Wed Jun 04, 2008 11:43 pm
by syntax24
Heres what I have:

Code: Select all

$announcements = mysql_query("SELECT * FROM announcements WHERE ato = $auth[userGroup] && WHERE ato = '0'") or die(mysql_error());
Obviously thats wrong as we all know... but how do I do something like that... i tried just an && without the 2nd WHERe... but that only pulled data that had both ato = usergroup and ato=0 .... i want to pull results IF ato is EITHER the usergroup OR 0, which is Global... I tried || but that still only listed 1 result... i have 2 in the database... 1 which ato is the group and 1 where its 0... so if it all works right, both should show.

heres the code i'm using to echo the results found...

Code: Select all

while ($announce = mysql_fetch_assoc($announcements)) {
                        echo "<tr>
                          <td width='23%' bgcolor=\"#F4F4F4\"><div align=\"center\"><em>"; 
                          
                          if($announce['ato'] == "1") { echo "Admins"; }
                          if($announce['ato'] == "2") { echo "Teachers"; }
                          if($announce['ato'] == "3") { echo "Parents"; }
                          if($announce['ato'] == "4") { echo "Students"; }
                          if($announce['ato'] == "5") { echo "Office"; }
                          if($announce['ato'] == "0") { echo "Global"; }
                          
                          echo "</em></div></td>
                          <td width=\"77%\" bgcolor=\"#F4F4FF\"><div align=\"left\"><a href='/view-announcements.php?id=".$announce['id']."' style='color:#000; text-decoration:none;'>".$announce['subject']."</a></div></td>
                        </tr>";
                        }
let me know if thats good or not too...

Re: how do i have multiple WHERE clauses???

Posted: Wed Jun 04, 2008 11:48 pm
by John Cartwright

Code: Select all

.. WHERE foo = 1 AND fee = 2

Re: how do i have multiple WHERE clauses???

Posted: Wed Jun 04, 2008 11:49 pm
by Benjamin
The syntax is below. That query won't work though because a table field can never be two values at once.

Code: Select all

 
SELECT
  *
FROM
  announcements
WHERE
  ato = $auth[userGroup]
  AND ato = '0';
 

Re: how do i have multiple WHERE clauses???

Posted: Thu Jun 05, 2008 9:51 am
by syntax24
So I guess I didn't catch it... will this work or not? Am I going to have to somehow combine 2 different queries to pull the data I need into one area?

Re: how do i have multiple WHERE clauses???

Posted: Thu Jun 05, 2008 2:40 pm
by Benjamin
Someone asked this question a few days ago. Please see viewtopic.php?f=2&t=83551 for the answer.