Re: selecting based on a month in a date
| From: | John W. Holmes | Date: | Thu, 28 Aug 2003 22:47:38 +0000 |
| Subject: | Re: selecting based on a month in a date | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-161087@lists.php.net to get a copy of this message | ||
Creative Solutions New Media wrote:
Hi, Asked this on the mySQL list but it seems to be more of a PHP syntax thing that a mySQL thing. In have the following line in PHP <?php $today = getdate();?> I have a mySQL table which contains dates formatted as dates(xxxx-xx-xx) I want to select all records based on a specific month. This is my select statement SELECT * FROM sti_tracking WHEREIt's returning the correct results for your query. I'm surprised it's even running. getdate() returns an array, btw, so you're looking for ros that match this:date= MONTHNAME('$today') = 'August' Cased in php it looks like so... <?php mysql_select_db($database_sti_tracking_DB, $sti_tracking_DB); $query_totalHitsMonth_RS_RS = "SELECT * FROM sti_tracking WHEREdate= MONTHNAME('$today') = 'August'"; $totalHitsMonth_RS_RS = mysql_query($query_totalHitsMonth_RS_RS, $sti_tracking_DB) or die(mysql_error()); $row_totalHitsMonth_RS_RS = mysql_fetch_assoc($totalHitsMonth_RS_RS); $totalRows_totalHitsMonth_RS_RS = mysql_num_rows($totalHitsMonth_RS_RS); ?> but this isn't working....it's returning no records which is wrong.
date = MONTHNAME('Array') = 'August'
You don't even need to call getdate(), just put
WHERE MONTHNAME(date) = 'August'
in your query.
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals – www.phparch.com