Re: [nmsinc] Sorting by name in options table
Hi nmsinc,
Try this instead:
<?php if ($CURRENT_USER['isAdmin']): ?>
Insurance Company:
<select name="member_company" onchange = "populateAdjusterList(this, 'insurance');">
<option value="">All</option>
<?php $companiesList = mysql_select("member_companies", "member_type = 'Insurance'"); ?>
<?php $numToName = array(); ?>
<?php foreach ( $companiesList as $company): ?>
<?php $numToName[$company['num']] = $company['member_company_name']; ?>
<?php endforeach; ?>
<?php asort($companiesList); ?>
<?php foreach ( $companiesList as $insurance): ?>
<option value = "<?php echo $insurance['num'];?>"><?php echo $insurance['member_company_name'];?></option>
<?php endforeach ?>
</select>
<?php endif; ?>
It just creates a temporary array of num to company name, sorts is alphabetically using asort (maintaining the key=>value assocation) and then runs another foreach to output the results.
Is this a workable solution? If not, it might be worthwhile to see what can be done with the ajax to improve things.
Let me know,
Tom