doushan6692 2016-05-26 14:23
浏览 10
已采纳

Codeigniter选择阵列位置

I have the following query:

  public function get_stuff() {

   $query = $this->db->query(
    'SELECT entry_type, COUNT(entries.type_id) AS totals
     FROM entries
     LEFT JOIN type ON entries.type_id = type.type_id
     GROUP BY entries.type_id'
   );

   return $query->result();

}

I used it to create a bar chart, works just fine. Thing is, I want to display another chart ( this time a pie chart ) in the same page that will use rows number 5 and 7 ( so, I believe it would be position 4 and 6 of the result array ). I know I could simply make another query, but I don't think it would be the optimal choice. How can I echo something like:

$data = $this->test_model->get_stuff();
echo $data->row(4)->totals;

Also, can I have multiple returns in my model? lets say I have $query1; $query2; and $query3; What's the correct way to return and access each query in my controller?

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dongmei1828 2016-05-26 14:29
    关注

    No need for another query, fetch the row like this:

        $data = $this->test_model->get_stuff();
        $entry_type= $data[4]->entry_type;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向