user3543275
user3543275

Reputation: 13

PHP populate formatted date (only month and year) into drop down list, but delete duplicates

Im trying to get the dates from the DB, store only the months and years of them into a var, populate the drop drown list with the results, but delete any duplicate month and year.

For example my drop down list is displaying:

And I only want it do to display one month (with year) each option.

Here's my code:

            <select name="month">
                <?php
                    $sSDate = "SELECT DISTINCT eventStartDate FROM te_events GROUP BY eventStartDate ORDER BY eventStartDate ASC";
                    $qrSDate = mysql_query($sSDate) or die (mysql_error());
                    while($rowSDate = mysql_fetch_assoc($qrSDate))
                    {
                        $s_event_start_date = $rowSDate ['eventStartDate'];

                        $sGetStartDate = strtotime($s_event_start_date);
                        $sFormattedStartDate = date('M y', $s_event_start_date );

                        echo '
                        <option value="'.$sFormattedStartDate.'">
                            '.$sFormattedStartDate.'
                        </option>
                        ';
                    }
                ?>
            </select>

Upvotes: 0

Views: 456

Answers (1)

Simone
Simone

Reputation: 247

Use sql: Select distinct Year(eventStartDate), month(eventStartDate) from ...

Upvotes: 2

Related Questions