[PHP-DB] 'OR' logic in mySQL query

2005-04-17 Thread Ron Piggott
Am I able to use the OR logic in mySQL queries?

$query = SELECT * FROM table WHERE date_received LIKE '$todays_date' OR
'$yesterdays_date' ORDER BY prayer_request_reference ASC;

In this above example will the  OR '$yesterdays_date'  work?

In reality I am wanting to preview new entries to the database within the
past 2 days

Ron

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] 'OR' logic in mySQL query

2005-04-17 Thread Mark Cain
You might want to pattern you SELECT statement in this manner:

SELECT * FROM `tablename` WHERE status = 3 OR status = 1

Notice I called the field name explicitly on each side of the OR.

Be sure to check the data type for the date field -- if it is a datetime
stamp or date stamp, it might complain with the use of like

You ought to check out:

http://dev.mysql.com/doc/mysql/en/where-optimizations.html

Mark Cain



- Original Message -
From: Ron Piggott [EMAIL PROTECTED]
To: PHP DB php-db@lists.php.net
Sent: Sunday, April 17, 2005 4:04 PM
Subject: [PHP-DB] 'OR' logic in mySQL query


 Am I able to use the OR logic in mySQL queries?

 $query = SELECT * FROM table WHERE date_received LIKE '$todays_date' OR
 '$yesterdays_date' ORDER BY prayer_request_reference ASC;

 In this above example will the  OR '$yesterdays_date'  work?

 In reality I am wanting to preview new entries to the database within the
 past 2 days

 Ron

 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] 'OR' logic in mySQL query

2005-04-17 Thread Miles Thompson
No - OR and AND tests work like this:
 (first conditional test) OR (second conditional test)
therefore
((date_received LIKE '$todays_date) OR (date_received LIKE 
'$yesterdays_date'))

And of course you will check the MySQL docs to confirm that OR does work in 
the WHERE clause, won't you?

Another way of handling the query is to ask for anything less than two days 
old, sort of like this:
where date_received = $today - 2. (And no, that's not accurate syntax.)

Regards - Miles
At 05:04 PM 4/17/2005, Ron Piggott wrote:
Am I able to use the OR logic in mySQL queries?
$query = SELECT * FROM table WHERE date_received LIKE '$todays_date' OR
'$yesterdays_date' ORDER BY prayer_request_reference ASC;
In this above example will the  OR '$yesterdays_date'  work?
In reality I am wanting to preview new entries to the database within the
past 2 days
Ron
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php