fogofogo Posted June 1, 2006 Share Posted June 1, 2006 Hello all,I am trying to populate a drop down menu with a mysql database. I was hoping to have a selection of months in the dropdown menu, based on date fields in my database (displayed like january, february, march, april, ,may etc)when a user then selects a month, they will be brought to a new page that will have only the records created in that month.But in my database, the date is stored in this format: 2006-05-12 00:00:00Is there any way that I could replace the dates with the months?for example : 2006 - 05, would be May 2006.if you need to see my code, here it is:[code]<? //database connection$query = mysql_query("SELECT * FROM casinocredit"); // start to print out the formecho "<form action=\"cats.php\" method=\"POST\"><select name=\"clients\"><option value=\"\" \"selected\">Select A Client</option>";// loop through the recordswhile ($row = mysql_fetch_array($query)){echo "<option value=\"{$row['ID']}\">{$row['ddate']}</option>";}echo "</select>";echo "<input type=\"submit\" value=\"Go\"></form>";?>[/code]Anyone have any advice or opinions?Thanks for your timeJ[code][/code] Quote Link to comment https://forums.phpfreaks.com/topic/10946-populating-a-dropdown-menu-with-a-mysql-database/ Share on other sites More sharing options...
MikoMak Posted June 1, 2006 Share Posted June 1, 2006 Hi,you probably want to use the mysql function date_format() to pull out just the month from the table e.g. something like$sql_date = mysql_query("SELECT date_format(ddate, '%M ') as ddate FROM casinocredit ")This will give you just the months by name and not the full date. (use '%M %Y' if you need the month and year e.g. May 2006 )hth. Quote Link to comment https://forums.phpfreaks.com/topic/10946-populating-a-dropdown-menu-with-a-mysql-database/#findComment-40881 Share on other sites More sharing options...
fogofogo Posted June 1, 2006 Author Share Posted June 1, 2006 [!--quoteo(post=379038:date=Jun 1 2006, 07:14 AM:name=MikoMak)--][div class=\'quotetop\']QUOTE(MikoMak @ Jun 1 2006, 07:14 AM) [snapback]379038[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hi,you probably want to use the mysql function date_format() to pull out just the month from the table e.g. something like$sql_date = mysql_query("SELECT date_format(ddate, '%M ') as ddate FROM casinocredit ")This will give you just the months by name and not the full date. (use '%M %Y' if you need the month and year e.g. May 2006 )hth.[/quote]Thats cool - cheers Miko Quote Link to comment https://forums.phpfreaks.com/topic/10946-populating-a-dropdown-menu-with-a-mysql-database/#findComment-40897 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.