以下拉优先级方式显示值

时间:2013-01-27 07:10:38

标签: php mysql

我有一个下拉列表,其中我有不同的位置,并且根据此位置下拉列表,我已显示属于相应位置的代理商。现在我已将代理分配给某个位置,因此分配的代理应显示在下拉列表的最后。我没有得到如何做到这一点。请帮忙.LIKE FIFO

1 个答案:

答案 0 :(得分:0)

基于缺少任何代码,一种(不是非常有效)的方式...

print "<select id="whatever">;
foreach ($arrAgents as $arrAgent) {
    if (empty($arrAgent['location'])) {
        printf('<option value="%s">%s</option>', $arrAgent['name'], $arrAgent['name']);
    }
}
foreach ($arrAgents as $arrAgent) {
    if (!empty($arrAgent['location'])) {
        printf('<option value="%s">%s</option>', $arrAgent['name'], $arrAgent['name']);
    }
}
print "</select>";

假设您正在处理数组,更好的方法是根据location元素对数组进行排序。这可能需要使用uasort进行用户定义的排序。