简体   繁体   中英

Codeigniter select array position

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.

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

    $data = $this->test_model->get_stuff();
    $entry_type= $data[4]->entry_type;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM