Hi,
I need to alphabetize a jump menu where I pull the data from a MySQL database. The current code I have is:
<form name="form2">
<select name="menu1" onChange="MM_jumpMenu('parent',this,0)">
<?php
do {
?>
<option value="lessonplans_edit.php?id=<?php echo $row_lplans_menu['ID']?>"><?php echo $row_lplans_menu['Unit_Title']?><?php echo $row_lplans_menu['Existing_Title']?> <?php echo $row_lplans_menu['LessonNo']; ?></option>
<?php
} while ($row_lplans_menu = mysql_fetch_assoc($lplans_menu));
$rows = mysql_num_rows($lplans_menu);
if($rows > 0) {
mysql_data_seek($lplans_menu, 0);
$row_lplans_menu = mysql_fetch_assoc($lplans_menu);
}
?>
</select>
</form>
I have two fields which need to be alphabetized. The first is Unit_Title and the second is Exisiting_Title. If there's a Unit_Title there's no Exisiting_Title and the same for the opposite direction.
What I was trying and didn't succeed at was putting the Unit_Title, LessonNo and ID in an array, sorting the array and then going through the array and putting the pieces into the JumpMenu.
Here's what I was trying, but didn't work:
<form name="form1">
<select name="menu1" onChange="MM_jumpMenu('parent',this,0)">
<?php
do {
$ID = $row_lplans_menu['ID'];
$title = $row_lplans_menu['Unit_Title'];
if($title == ""){
$title = $row_lplans_menu['Existing_Title'];
}
$lnumb = $row_lplans_menu['LessonNo'];
$menu_array = array($title, $lnumb, $ID);
$menu[] = implode(", ",$menu_array);
} while ($row_lplans_menu = mysql_fetch_assoc($lplans_menu));
$rows = mysql_num_rows($lplans_menu);
if($rows > 0) {
mysql_data_seek($lplans_menu, 0);
$row_lplans_menu = mysql_fetch_assoc($lplans_menu);
}
usort ($menu, "strnatcmp");//alphabetizes array
//$menu[] = explode(", ",$menu);
for( $i = 0 ; $i < count($menu) ; $i++ ) {
//list ($o_title, $o_lesson, $o_id) = split ('[,.-]', $menu[$i]);
?>
<option value="lessonplans_edit.php?id=<?php echo $o_id; ?>"<?php if (!(strcmp($o_id, $o_id))) {echo "SELECTED";} ?>>
<?
echo "$o_title $o_lesson ID: $o_id";
?>
</option>
<? } ?>
</select>
</form>
Any suggestions on how to alphabetize this drop down menu?
Thanks,
Barak
😕