I see from reading other posts on this site, there a similar solutions to what I am trying to do, but as I’m building in Dreamweaver, some of the syntax is different and I’m not sure what parts I need.
I think there’s an If {} statment to add, just not sure where…
So I have a page for selecting a from a list of cruise holidays, the user chooses where they would like to go from a drop down menu, that then shows the cruises going to that destination. Easy. Next, they can choose when they would like to travel, narrowing the search result down with a jump menu to a particular month
So my first set of records are all the cruises going to say the Caribbean.
There are four, two in April 2012 and two in May 2012.
So I’ve got all four showing in my list, but now I want the user to pick a month, and by populating the jump menu with the destination-filtered recordset, I get four choices
April 2012
April 2012
May 2012
May 2012
What I actually want is
April 2012
May 2012
If I group the records by month in the MySQL query, I don’t get all four cruises in the destination list, which we want.
Here’s the code for the Month selector menu
<select name="jumpMenu2" id="jumpMenu2" onchange="MM_jumpMenu('parent',this,0)">
<option value="">Select a date</option>
<?php do { ?>
<option value="chooseacruise.php?destination=<?php echo urlencode($row_cruises['destination']);?>&<?php echo $row_cruises['departs']?>"><?php echo date('F Y', strtotime($row_cruises['departs'])); ?></option>
<?php } while ($row_cruises = mysql_fetch_assoc($cruises));
$rows = mysql_num_rows($cruises);
if($rows > 0) {
mysql_data_seek($cruises, 0);
$row_cruises = mysql_fetch_assoc($cruises);
}
?>
</select>
The while loop is Dreamweaver’s standard loop to populate the menu. What I want to is write the month, then at the next row, if the month is the same, ignore it.
Thanks in advance
Rich 🙂
Firstly, this has nothing to do with Dreamweaver. The syntax is the same. Here is a simple solution for you:
Please be aware that you have to order the sql query by departs.