I want to make a dropdownlist that retrieve the values from the database. The values are the month and the year of the date of user input. The dropdownlist example:-
- --Select Month--
- 11-2013
- 12-2013
- 03-2015
- 02-2016
I have done the query to get the result as above:-
SELECT DISTINCT(DATE_FORMAT(DATE(date),'%m-%Y')) AS date
FROM tbl
ORDER BY DATE_FORMAT(DATE(date),'%Y'), DATE_FORMAT(DATE(date),'%m')
ASC
However, I'm quite confused on how to display all of other columns in tbl
after selecting the month in the dropdownlist. Say, in the table tbl
, there are description
and personInCharge
column aside the date
column. When selecting the month in the dropdownlist, it suppose to retrieve all data that is related with the selected month.
I've tried using these:-
SELECT *, DISTINCT(DATE_FORMAT(DATE(date),'%m-%Y')) AS date
FROM tbl
ORDER BY DATE_FORMAT(DATE(date),'%Y'), DATE_FORMAT(DATE(date),'%m')
ASC
and
SELECT description, personInCharge, DISTINCT(DATE_FORMAT(DATE(date),'%m-%Y')) AS date
FROM tbl
ORDER BY DATE_FORMAT(DATE(date),'%Y'), DATE_FORMAT(DATE(date),'%m')
ASC
and such but all I get is error. Where am I wrong? How am I to complete this? Is it by using join clause? If so, how?
--UPDATE--
I get to list out the details by using this query:-
SELECT *, (DATE_FORMAT(DATE(date),'%m-%Y'))AS month FROM tbl
But, I still don't know how to integrate with the dropdownlist.