Forum Moderators: coopster

Message Too Old, No Replies

Advanced Dynamic Menu Display (MySQL)

Advanced Dynamic Menu Display (MySQL)

         

amdorsey

9:01 pm on Dec 6, 2004 (gmt 0)

10+ Year Member



I have a pulldown menu being dynamically populated by a database

Code:

<option value="">Choose a Beginning Date</option>
<?php
do {
?>
<option value="<?php echo $row_Date_Sorter['event']?>"><?php echo $row_Date_Sorter['event']?></option>
<?php
} while ($row_Date_Sorter = mysql_fetch_assoc($Date_Sorter));
$rows = mysql_num_rows($Date_Sorter);
if($rows > 0) {
mysql_data_seek($Date_Sorter, 0);
$row_Date_Sorter = mysql_fetch_assoc($Date_Sorter);
}
?>
</select>

I want to be able to just display unique values (hard to explain)

Basically, if I have a column "event" and in that "event" column I have the following values (christmas, thanksgiving, easter, christmas, easter)

In the pulldown I want to display...

Christmas
Easter
Thanksgiving

NOT -->

Christmas
Thanksgiving
Easter
Christmas
Easter

So, I need to filter out duplicate names for the "event" field, So when I make a selection from the pulldown, it sorts the database based on that event.

Hope this makes sense geniouses. You guys have answered questions Macromedia can't answer! Lets see about this one! haha.

Thanks All,
Adam[/php_man]

dmorison

9:05 pm on Dec 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your query isn't in your code snippet above; but you might be able to use the DISTINCT keyword...

Instead of:

SELECT event FROM table

use:

SELECT DISTINCT event FROM table

and this will get rid of duplicates at source.

baze22

9:06 pm on Dec 6, 2004 (gmt 0)

10+ Year Member



You could use the DISTINCT option in you query. like this:

SELECT DISTINCT event from eventtable

this prevents duplicate rows in the result.

baze

edited: I gotta learn to type faster. ;) and iI had it reversed too.

amdorsey

9:18 pm on Dec 6, 2004 (gmt 0)

10+ Year Member



Thanks,
Didn't realize you had all those sort options in the SQL query.

You Da Man!