tags:

views:

64

answers:

4

Can anyone give me some examples to make query which has more than one WHERE statements please?

I have the following query and I want to add WHERE privacy = 'public'

$query = $this->db->query("SELECT DATE_FORMAT(eventDate,'%d') AS 
day,eventContent,eventTitle,id FROM eventcal WHERE eventDate BETWEEN 
'$current_year/$current_month/01' AND '$current_year/$current_month
/$total_days_of_current_month'");

Thanks in advance.

+2  A: 

Use:

AND privacy = 'public'
Lasse V. Karlsen
A: 

Change the WHERE to AND:

AND privacy = 'public'

In full, and made more readable:

SELECT DATE_FORMAT(eventDate,'%d') AS day,
       eventContent,
       eventTitle,
       id
FROM   eventcal
WHERE  eventDate BETWEEN '$current_year/$current_month/01'
                     AND '$current_year/$current_month/$total_days_of_current_month'
AND    privacy = 'public'
Mark Byers
+3  A: 

[..] WHERE privacy = 'public' AND (eventDate BETWEEN [..] ) ?

Darmen
+2  A: 

I don't know anything about MySql specifically, but it looks like you just need another AND statement:

$query = $this->db->query("SELECT DATE_FORMAT(eventDate,'%d') AS day,eventContent,eventTitle,id FROM eventcal WHERE
eventDate BETWEEN '$current_year/$current_month/01'
AND '$current_year/$current_month/$total_days_of_current_month'
AND privacy='public'");

Henrik Söderlund