Php codeigniter中Mysql中的行百分比

Php codeigniter中Mysql中的行百分比,php,mysql,codeigniter,Php,Mysql,Codeigniter,下面是我的模型代码,它获取表中所有问题的百分比 $public function ques() { #get all question count $query= $this->db->query("SELECT * FROM questions"); $result = $query->result_array(); $count = count($result); $limit = ($count/100)*50; # sel

下面是我的模型代码,它获取表中所有问题的百分比

$public function ques()
{
   #get all question count
   $query= $this->db->query("SELECT * FROM questions");
   $result = $query->result_array();
   $count = count($result);  

   $limit = ($count/100)*50;  

   # select only limited question which set with $limit
   $query= $this->db->get("Questions" , $limit);
   $result = $query->result_array();
   return $result;
}
共有四列: 1.问题号 2.问题 3.考试id 4.章


我需要的是,不获取每章的行数,获取百分比行数,而不是只计算所有问题并返回代码中所示的结果。谢谢您

查看分组依据。请您重新编写包含分组依据的查询,好吗?请您试一试,展示您的想法,我们可以从中提供帮助。此外,提供一个包含预期结果的样本数据集总是很有帮助的。$query=$this->db->querySELECT chapter,COUNT*从考试id=7的问题中逐章分组;但是它不起作用:试试$this->db->select'*'->from'questions'->where'exam\u id',7->group\u by'chapter'->get;