SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist cturner01's Avatar
    Join Date
    Jun 2006
    Location
    My computer
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow Dates from database into combo boxes?

    Can someone please tell me how I can place dates from a database into combo boxes? I want the database date to be selected in the combo box. I have placed some of my code below. I am stuck. Thanks in advance.

    PHP Code:
    $days = array("Monday""Tuesday""Wednesday""Thursday""Friday""Saturday""Sunday");
    $months = array("January""February""March""April""May""June""July""August""September""October""November""December");
    $thisDay date("l");
    $thisDate date("j");
    $thisMonth date("F");
    $thisYear date("Y");
            
       print 
    "<select name=\"selectDay\" id=\"selectDay\">";
    foreach(
    $days as $a) {
       
    $selStr $a == $thisDay " selected=\"selected\"" "";
       print 
    "<option value=\"$a\"$selStr>$a</option>";
    }
       print 
    "</select>";
            
       print 
    "<select name=\"selectDate\" id=\"selectDate\">";
    for(
    $i=1$i<=$lastDate$i++) {
        
    $selStr $i == $thisDate " selected=\"selected\"" "";
        print 
    "<option value=\"$i\"$selStr>$i</option>";
    }
        print 
    "</select>";
            
        print 
    "<select name=\"selectMonth\" id=\"selectMonth\">";
    foreach(
    $months as $v) {
        
    $selStr $v == $thisMonth " selected=\"selected\"" "";
        print 
    "<option value=\"$v\"$selStr>$v</option>";
    }
        print 
    "</select>";

        print 
    "<select name=\"selectYear\" id=\"selectYear\">";
    for(
    $i=$thisYear$i<$thisYear+30$i++) {
        
    $selStr $i == $thisYear " selected=\"selected\"" "";
        print 
    "<option value=\"$i\"$selStr>$i</option>";
    }
        print 
    "</select>"
    Last edited by cturner01; Jan 11, 2007 at 14:51.

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    one example would be to set $thisDay to the day from your db.

    you could do
    $thisDay = date("l", $timestamp_from_db);

    see the mysql function UNIX_TIMESTAMP() or php's strtotime() if you need to convert from datetime. or you could just use DATE_FORMAT() in your query to get the right peices.


Bookmarks

Posting Permissions

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