PHP in dropdown menu's
| From: | Tim Thorburn | Date: | Mon, 16 Sep 2002 08:18:06 +0000 |
| Subject: | PHP in dropdown menu's | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-116493@lists.php.net to get a copy of this message | ||
Hi,
I've got a rather large database setup in MySQL for an Event Calendar. As its grown in size over the years, editing it has become rather tedious. To simplify things I'm trying to setup a dropdown menu where the administrator of the Calendar will choose the year in which they would like to edit - so that the Calendar can be fully automated I thought the best approach would be to query the database to see what years are present, and then display those years in the dropdown menu.
I've got it partially working - it lists years, but all the years for every entry in the database (ie. several hundred 2000's, 2001's, 2002's, and 2003's). I'd like it to list only one of each of the years that is in the database (ie. 2000, 2001, 2002, 2003, etc). I must be missing something rather simple ... hopefully because its 3.15am :P - I'll post my code below.
TIA,
-Tim
<?
$row_ComCalYear = mysql_fetch_assoc($ComCalYear);
$totalRows_ComCalYear = mysql_num_rows($ComCalYear);
?>
<select name="Year" id="Year">
<option value="value" <?php if (!(strcmp("value", $row_ComCalYear['EventYear']))) {echo "SELECTED";} ?>>label</option>
<?php
do {
?>
<option value="<?php echo $row_ComCalYear['EventYear']?>"<?php if (!(strcmp($row_ComCalYear['EventYear'], $row_ComCalYear['EventYear']))) {echo "SELECTED";} ?>><?php echo $row_ComCalYear['EventYear']?></option>
<?php
} while ($row_ComCalYear = mysql_fetch_assoc($ComCalYear));
$rows = mysql_num_rows($ComCalYear);
if($rows > 0) {
mysql_data_seek($ComCalYear, 0);$row_ComCalYear = mysql_fetch_assoc($ComCalYear); } ?>
</select>