dougu1896 2017-05-25 10:38
浏览 156

多个选择查询与单个where子句?

I am creating a messaging system. In which there are two type of user admin and user.
Admin can send message to all user and user can send message to admin.
I am trying to fetch,

$this->db->select("user_from,count(user_from)as total");
$this->db->from("messages");
$this->db->group_by("user_from");
$query = $this->db->get();
return $query->result_array();

$this->db->select("*");
$this->db->from("messages");
$this->db->where("user_to","admin");
$query = $this->db->get();
return $query->result_array();

In single both the query work correctly.
I want to include both query in one.
I want to run multiple select query using single where clause which show the last message send by user to admin.
can anyone give me any idea?

table screenshot model code

  • 写回答

6条回答 默认 最新

  • douzhen5158 2017-05-25 10:48
    关注

    Your Controller

    $this->db->where("user_to","admin");
    $this->db->group_by("user_from");
    $query = $this->db->get('messages');
    $data['result'] = $query->result_array(); // Your Result Array
    $data['total'] = $query->num_rows(); // total number of records
    
    // You can pass $data in any view file here
    

    Your View

    print_r($result); // result array
    echo $total; // total number of records
    
    评论

报告相同问题?

悬赏问题

  • ¥15 制裁名单20240508芯片厂商
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致