Re: Is there a way to display data from database for Select Options in a form?
| From: | Mike Smith | Date: | Tue, 10 Jan 2006 16:53:27 +0000 |
| Subject: | Re: Is there a way to display data from database for Select Options in a form? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-228437@lists.php.net to get a copy of this message | ||
On 1/10/06, Sue <skot1@twcny.rr.com> wrote:
> Hello,
>
> We have a form that contains a Select option for a listing of available
> dates for the user to choose from. Right now we have to manually change the
> dates within the form's Selection list as new dates become available to
> choose from. We currently store these available dates in our database, and
> am wondering if we can somehow extract these dates from the table to display
> in our form? This would eliminate alot of maintenance needed to this form.
> If anyone has any ideas as to reference material etc. that I may look which
> would give me an idea how to do this using PHP, I'd appreciate it!
How about...
$format = "m/d/Y";
$sql = "SELECT datefield FROM table";
$results = $whatever_db_abstraction_your_using_to_execute__sql($sql);
<select name="date">
<?php
foreach($results AS $result){
echo "<option>".date($format,strtotime($result))."</option>";
}
?>
</select>
http://us2.php.net/manual/en/function.strtotime.php
http://us2.php.net/manual/en/function.date.php
Mike