Re: PHP in dropdown menu's
| From: | Justin French | Date: | Mon, 16 Sep 2002 08:43:59 +0000 |
| Subject: | Re: PHP in dropdown menu's | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-116497@lists.php.net to get a copy of this message | ||
Hi,
Something like to do with DISTINCT... maybe:
SELECT DISTINCT year FROM table ORDER BY year ASC ... or soemthing like
that.
The mysql manual's select page will help nail the exact syntax nailed.
http://www.mysql.com/doc/en/SELECT.html
Justin French
on 16/09/02 6:18 PM, Tim Thorburn (immortal@nwconx.net) wrote:
> 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>
>
>