dqq46733 2015-09-27 12:19
浏览 35

从MySQL中选择最后N行 - codeigniter

I'm using codeigniter;

I would like to get last N rows from my table.

In my query I want to get last 200 rows:

         $this->m_general->select('count(*)');
         $this->m_general->from('pm');
         $result_count_query = $this->m_general->get();
         $count_query = $result_count_query->num_rows();



$data['all']     = $this->m_general->get('pm', array( 'admin_delete'=>0 ) , $count_query-200,$count_query, array('admin_seen'=>'asc' , 'id'=>'desc') );

but it returns nothing.

where is my wrong ?

updated

below query not worked fine and it returns all records :

$data['all']     = $this->m_general->get('pm', array( 'admin_delete'=>0 ) ,200, array('admin_seen'=>'asc' , 'id'=>'desc') );
  • 写回答

2条回答 默认 最新

  • donglisi8644 2015-09-27 13:45
    关注

    Check out the API

    https://ellislab.com/codeigniter/user-guide/database/active_record.html

    Looks like you can't do this with the get method. Build your query according to the API.

    $this->m_general->limit(200);
    $this->m_general->order_by("admin_seen", "asc");
    $this->m_general->order_by("id", "desc"); 
    
    $data['all']     = 
    $this->m_general->get('pm', array( 'admin_delete'=>0 ));
    
    评论

报告相同问题?