我如何才能将下拉列表置于上升状态


How can I put a dropdown list in a ascendant?

我需要把名字放在升序列表中。

这是我的观点。。。

 <select name="characters" id="characters">
            <option value="">-</option>
            <?php foreach($characters as $character):?>
            <option value="<?php echo $character->id; ?>"><?php echo $character->name; ?></option>
            <?php endforeach; ?>

这是我的模特。我用它来获取数据表单DB。

 public function get_users_by_type ($user_type_tag, $count='', $offset='', $searchvalue='')
{
    if (empty ($user_type_tag))
        return FALSE;
    $name   = !isset ($searchvalue['name']) ? '' : $searchvalue['name'];
    $this->db->select ('users.*, tag, UNIX_TIMESTAMP(joined) AS timestamp, user_types.name AS user_type_name, user_types.modified AS user_type_modified');
    $this->db->from ('users');
    $this->db->join ('user_types', 'users.user_type_id = user_types.id', 'inner');
    $this->db->where ('user_types.tag', $user_type_tag);
    $this->db->limit($count, $offset);
    $this->db->like ('users.name',$name );
    $result = $this->db->get();

根据您提供的代码,您正在循环通过对象的数组。sort()方法将对基本数组进行排序。

请参阅php.net排序

对数据进行排序最有效的方法是在从数据库中检索ORDERBY子句时对其进行排序,该子句为Fallen&andrewsi推荐。