php - CodeIgniter, how to return multiple queries from model to controller? -


i'm trying model return 2 queries, 1 data multiple records table 'categories', , count field, table 'posts'.

i've tried alot of possible solutions, far none fixed me.

my view work correct route /forum/$id, loading categories , post count per category won't work.

categories controller:

$this->load->database(); $this->load->model("categories_model");  $results=$this->categories_model->getcategories();  $data=array('results'=>$results);  $this->load->view('categories_view',$results); 

categories model:

// works if want categories   // $query=$this->db->get('categories'); // return $query->result();  $query1 = $this->db->get('categories'); $query2 = $this->db->query("select count(*) rowcount posts");  $return array('categories' => $query1, 'count' => $query2); 

categories view:

<tbody>     <?php foreach ($results['categories'] $r):?>         <tr>             <td><a href="<?php echo site_url('forum'); ?>/<?=$r->categorieid?>"><?=$r->name?></a></td>             <td><?=$r->rowcount?></td>         </tr>     <?php endforeach;?>  </tbody> 

when load categories view, error:

syntax error, unexpected 'array' (t_array), filename: models/categories_model.php

can me sample code on how this, or fix current code?

thank in advance!

return wrong in code remove $ return type

$return array('categories' => $query1, 'count' => $query2); 

it should be

return array('categories' => $query1, 'count' => $query2); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -