代码之家  ›  专栏  ›  技术社区  ›  pixeltocode

Codeigniter-对从MySQL检索到的值进行排序

  •  4
  • pixeltocode  · 技术社区  · 14 年前

    是否可以对从MySQL检索到的值进行排序,比如降序排序 id

    谢谢。

    3 回复  |  直到 14 年前
        1
  •  7
  •   vikmalhotra    14 年前

    干得好。。。

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

    在中阅读更多 codeigniter documentation for active record class .

        2
  •  5
  •   So Over It    14 年前

    $this->db->select('*')->from('table')->order_by('id', 'desc');
    $query = $this->db->get();
    
        3
  •  2
  •   mstafkmx    12 年前

    举个例子:

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