RE: [PHP] PHP in dropdown menu's
| From: | Richard Black | Date: | Mon, 16 Sep 2002 08:32:17 +0000 |
| Subject: | RE: [PHP] PHP in dropdown menu's | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-116495@lists.php.net to get a copy of this message | ||
You haven't included your query in the code below, but I would guess you
are looking for something like:
SELECT DISTINCT year
FROM table
ORDER BY year
The DISTINCT keyword restricts the result set to rows which are
different. So if all you are returning is the year, rather than several
hundred 2000's it would give you 1.
HTH,
Richy
==========================================
Richard Black
Senior Developer, DataVisibility Ltd - http://www.datavisibility.com
Tel: 0141 951 3481
Email: rblack@datavisibility.co.uk
-----Original Message-----
From: Tim Thorburn [mailto:immortal@nwconx.net]
Sent: 16 September 2002 09:18
To: php-general@lists.php.net
Subject: [PHP] PHP in dropdown menu's
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>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php