COUNT / GROUP BY with active record?

后端 未结 5 2141
既然无缘
既然无缘 2020-12-01 12:02

I have a table with the following info:

id  |  user_id  |  points
--------------------------
1   |  12       |  48
2   |  15       |  36
3   |  18       |  2         


        
5条回答
  •  一整个雨季
    2020-12-01 12:37

    This code counts rows with date range:

    Controller:

    $this->load->model("YourModelName");
    $data ['query'] = $this->YourModelName->get_report();
    

    Model:

      public function get_report()
         {   
           $query = $this->db->query("SELECT  *
    FROM   reservation WHERE arvdate <= '2016-7-20' AND  dptrdate >= '2016-10-25' ");
           return $query;
         }
    

    where 'arvdate' and 'dptrdate' are two dates on database and 'reservation' is the table name.

    View:

    num_rows();
    ?>
    

    This code is to return number of rows. To return table data, then use

    $query->rows();
    return $row->table_column_name;
    

提交回复
热议问题