【发布时间】:2013-11-19 04:43:59
【问题描述】:
我需要把名字放在升序列表中。
这是我的看法……
<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();
【问题讨论】:
-
如果您从数据库中获取
$characters,则基于名称字段。顺便分享更多代码并说明问题所在。 -
这是此下拉菜单的完整代码。
-
@JonathanPadilla -
$characters来自哪里? -
@JonathanPadilla - 然后按照 Fallen 的建议 - 从数据库中将 ORDER BY 子句添加到您的 SELECT 中,您可以通过这种方式指定顺序。
-
我不能使用 sort()???
标签: php html codeigniter