RE: [PHP] question about for loop and mysql dates
| From: | John W. Holmes | Date: | Wed, 23 Apr 2003 00:03:47 +0000 |
| Subject: | RE: [PHP] question about for loop and mysql dates | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-144925@lists.php.net to get a copy of this message | ||
> Ok...been searching on google and the archives for a while now,
nothing
> is jumping up and giving me a clue :-)
>
> I am trying to build a drop-down box with a range of dates (mysql
> formatted):
>
> $result = mysql_query($sql)
> $row = mysql_fetch_array($result);
> $time_start = $row["time_period_start"];
> $time_end = $row["time_period_end"];
>
> for ($count=1; $count<=$time_end; $count++) {
> echo "<option value='" . $count . "'>" . $count .
> "</option>";
> }
One method, I'm sure there are others:
$start = strtotime($row['time_period_start']);
$end = strtotime($row['time_period_end']);
while($start < $end)
{
$d = date('Ymd',$start);
printf('<option value="%d">%d</option>',$d,$d);
$start += 86400;
}
May need some adjustment so $end date is included.
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/