Jump to content


Photo

populating a dropdown menu with a mysql database


  • Please log in to reply
2 replies to this topic

#1 fogofogo

fogofogo
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 01 June 2006 - 11:49 AM

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:

<? 

//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>";
?>

Anyone have any advice or opinions?

Thanks for your time

J

#2 MikoMak

MikoMak
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 01 June 2006 - 12:14 PM

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.

#3 fogofogo

fogofogo
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 01 June 2006 - 01:11 PM

[!--quoteo(post=379038:date=Jun 1 2006, 07:14 AM:name=MikoMak)--][div class=\'quotetop\']QUOTE(MikoMak @ Jun 1 2006, 07:14 AM) View Post[/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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users