www.webdeveloper.com
Results 1 to 3 of 3

Thread: populating a dropdown menu from a database

  1. #1
    Join Date
    Dec 2005
    Posts
    58

    populating a dropdown menu from a database

    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:

    PHP 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>";
    ?>
    Anyone have any advice or opinions?

    Thanks for your time

    J

  2. #2
    Join Date
    May 2006
    Location
    Portsmouth, Uk
    Posts
    99
    you need to use the following function
    date('M-Y'),strtotime($row['ddate']))
    this function will display the date in the wanted format
    reply for more information

  3. #3
    Join Date
    Jul 2004
    Location
    West Coast, Canada
    Posts
    665
    Change your query to
    PHP Code:
    $query "SELECT ID, DATE_FORMAT(ddate, '%b %Y') FROM casinocredit"

    The output should be your dropdown with dates formatted like this: Jan 2005, Feb 2005, etc.

    "Everything in a web browser."

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles