Jump to content

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]
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.
[!--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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.