I need to create a drop down list that will only show the previous 7 dates from a date stored in mysql database
<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:
<?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: