Jump to content

Archived

This topic is now archived and is closed to further replies.

fogofogo

populating a dropdown menu with a mysql database

Recommended Posts

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:00

Is 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 form

echo "<form action=\"cats.php\" method=\"POST\"><select name=\"clients\"><option value=\"\" \"selected\">Select A Client</option>";

// loop through the records

while ($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 time

J[code][/code]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[!--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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.