Re: 'OR' logic in mySQL query

From: Date: Mon, 18 Apr 2005 00:42:30 +0000
Subject: Re: 'OR' logic in mySQL query
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-39214@lists.php.net to get a copy of this message
* Ron Piggott <ron.php@actsministries.org>: > 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 First off, did you try it? You could have tried it and had a more specific question in the time it took you to ask the above question. Second: In SQL, as in PHP, an OR requires that you have the values you're testing against on either side. To be specific, '$yesterdays_date' is a true value, and it's not what you're testing; you're wanting to see if date_received is like that value -- inother words, date_received LIKE '$yesterdays_date' is what you're actually trying to test. That said, you'll get much better results with: SELECT * FROM table WHERE date_received LIKE '$todays_date' OR date_received LIKE '$yesterdays_date' ORDER BY prayer_request_reference ASC -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association | http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:matthew@garden.org | http://vermontbotanical.org

« previous php.db (#39214) next »