show previous 7 days in drop down list

Discussion in 'PHP' started by tapigy, Jun 6, 2007.

  1. #1
    I need to create a drop down list that will only show the previous 7 dates from a date stored in mysql database
     
    tapigy, Jun 6, 2007 IP
  2. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #2
    
    <select name="something">
    <?php
    	$current_date = time(); // or the time in the database
    	
    	// if this is stored as a DATETIME or something in mysql then you will need to strtotime($current_date)
    	// to make it a unix timestamp
    
    	for ($x = 0; $x <= 6; $x++)
    	{
    		echo '<option>'.date("F d Y g:iA",$current_date).'</option>';
    		$current_date -= 86400;
    	}
    ?>
    </select>
    
    PHP:
     
    ansi, Jun 6, 2007 IP
  3. tapigy

    tapigy Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    how do you do the strtotime or any one else got any ideas of another way
     
    tapigy, Jun 6, 2007 IP
  4. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #4
    
    <?php
    
    	// db connect stuff here
    	
    	$sql = "select mytime from tbl1";
    	$result = mysql_query($query) or die("query error");
    	$row = mysql_fetch_row($result);
    	$current_date = strtotime($row[0]); // convert the string formatted date into a unix timestamp
    
    	// loop through the days
    
    	for ($x = 0; $x <= 6; $x++)
    	{
    		echo '<option>'.date("F d Y g:iA",$current_date).'</option>';
    		$current_date -= 86400;
    	}
    
    ?>
    
    PHP:
     
    ansi, Jun 6, 2007 IP