开发者

Codeigniter - sort retrieved values from MySQL

开发者 https://www.devze.com 2023-01-12 04:25 出处:网络
Is it possible to sort the values retr开发者_如何学Cieved from MySQL, in say descending id? Thanks.Here you go...

Is it possible to sort the values retr开发者_如何学Cieved from MySQL, in say descending id?

Thanks.


Here you go...

$this->db->select("*");
$this->db->from("table");
$this->db->order_by("id", "desc");
$this->db->get();

Read more over in codeigniter documentation for active record class.


As ShiVik suggested, you can do this via the Active Record class quite easily. Also note that you can chain your queries together if you are using PHP 5+:

$this->db->select('*')->from('table')->order_by('id', 'desc');
$query = $this->db->get();


An exemple:

$query = $this->db->order_by("id", "desc")->get('table');
if($query->num_rows>0){
   foreach ($query->result() as $row){
      $names[] = $row->name;
   }
   return $names;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消