flashermx Posted December 28, 2006 Share Posted December 28, 2006 I have a MySQL table containing a date column that is formatted as per MySQL year-month-dayIn creating a search form in Dreamweaver 8 I developed a sql query to poulate a drop-down list menu containing all available months refomatted the way I want. See below:SELECT DISTINCT DATE_FORMAT(sweventcalendar.eventdate, '%M') AS fomattedeventmonthFROM sweventcalendarWHERE sweventcalendar.eventdate >= NOW()However, when I pass the form variable, the selection from the drop-down list, which is called eventmonth, using the GET action, I get no results.I know my querry works if I remove the date format from the code above and simply populate the drop-down list menu with all distinct dates represented by years-month-day.My querry results is coded as follows:SELECT sweventcalendar.eventtitle, sweventcalendar.eventdesc, sweventcalendar.eventurl1, sweventcalendar.eventurl2, sweventcalendar.eventurl3, DATE_FORMAT(sweventcalendar.eventdate, '%M %e, %Y') AS fomattedeventdateFROM sweventcalendarWHERE eventdate = colname/*colname is a date type with a default value of -1 and a run time value of $_GET['eventmonth'] */I would like query the table by month only.Any help would be appreciated.PS: is there something with the way I formated the date in setting up the form element that removes its value? Quote Link to comment Share on other sites More sharing options...
printf Posted December 29, 2006 Share Posted December 29, 2006 If you want to compare a month, then you need to tell the database that. If $_GET['eventmonth'], is numeric (1, 2, 3, ...), then...[code]... WHERE MONTH ( eventdate ) = intval ( $_GET['eventmonth'] );[/code]Or if your trying to compare a month name, (May, June, july)[code]... WHERE MONTHNAME ( eventdate ) = '" . mysql_real_escape_string ( $_GET['eventmonth'] ). "'"; mysql 5.0.25 or ^[/code]Or you could use....[code]... WHERE DATE_FORMAT(eventdate, '%M') = '" . mysql_real_escape_string ( $_GET['eventmonth'] ). "'";[/code]There all kinds of different ways to do this, what way is best, depends on how your using the result, these are just a few basic ways.printf Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.