Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从数据库中查询HTML表内容的数据_Php_Jquery_Codeigniter - Fatal编程技术网

Php 如何从数据库中查询HTML表内容的数据

Php 如何从数据库中查询HTML表内容的数据,php,jquery,codeigniter,Php,Jquery,Codeigniter,我使用codeigniter作为框架,后端使用php,前端使用javascript。我的数据库中有一个叫做“销售收入”的表: 如何查询数据并将其放入html表中? 我希望他们按产品和渠道进行分组,并根据分组计算总收入。 我希望html表中的结果如下所示: | channel | drug a | drug b | | hospital | 2000 | 1000 | | store | 1000 | 0 | |

我使用codeigniter作为框架,后端使用php,前端使用javascript。我的数据库中有一个叫做“销售收入”的表:

如何查询数据并将其放入html表中? 我希望他们按产品和渠道进行分组,并根据分组计算总收入。 我希望html表中的结果如下所示:

|  channel   |   drug a  | drug b    | 
|  hospital  |   2000    | 1000      |
|  store     |   1000    | 0         |
|  channel   |   drug a  | drug b    | 
|  hospital  |   66.67%  |  33.33%   |
|  store     |   100%    | 0%        |
$data = $this->db->like('product','drug a')->group_by('channel')->select_sum('revenue')->select('channel')->get('sales_revenue');
然后将收入换算成如下百分比:

|  channel   |   drug a  | drug b    | 
|  hospital  |   2000    | 1000      |
|  store     |   1000    | 0         |
|  channel   |   drug a  | drug b    | 
|  hospital  |   66.67%  |  33.33%   |
|  store     |   100%    | 0%        |
$data = $this->db->like('product','drug a')->group_by('channel')->select_sum('revenue')->select('channel')->get('sales_revenue');
我希望最后一个表出现在web上

我尝试过这样构建查询:

|  channel   |   drug a  | drug b    | 
|  hospital  |   2000    | 1000      |
|  store     |   1000    | 0         |
|  channel   |   drug a  | drug b    | 
|  hospital  |   66.67%  |  33.33%   |
|  store     |   100%    | 0%        |
$data = $this->db->like('product','drug a')->group_by('channel')->select_sum('revenue')->select('channel')->get('sales_revenue');

但此查询只会导致产品“Druge a”,当有空值时,表会因为空值而出错。

情况如何?你还需要帮助吗?是的,我需要帮助你如何计算66.67%和33.33%的值?(2000/(2000+1000))*100=66.7%,(1000/(2000+1000)*100=33.33%我还不知道你是如何计算的。你能再解释一下吗。