Welcome Guest, Not a member yet? Register   Sign In
Select statement not returning the value
#1

[eluser]cerberus478[/eluser]
Hi I'm doing a select statement using active records. When I print_r($data) to see if it is returning the values all i get is

Quote:Array ( [menus] => ) 1

I have 2 records in my table.

menus controller
Code:
function order_ajax(){
     $data['menus'] = $this->menus_model->get_all();
     echo print_r($data);
                
     $data['view_file'] = "order_ajax";
    
     $this->load->view('order_ajax', $data);
        
               }

and my menus_model

Code:
function get_table() {
  $table = "menus";
  return $table;
}


function get_all(){
  $table = $this->get_table();
  $query = $this->db->get('$table');
  return $query;
}
#2

[eluser]noideawhattotypehere[/eluser]
Code:
return $query->result_array();
#3

[eluser]cerberus478[/eluser]
I tried that and I got
Quote:Fatal error: Call to a member function result_array() on a non-object in /Applications/MAMP/htdocs/untitled/application/modules/menus/models/menus_model.php on line 26
#4

[eluser]CroNiX[/eluser]
Code:
$query = $this->db->get('$table');

Remove the single quotes from around $table. You are turning the variable into a literal string of "$table" instead of what $table contains.
#5

[eluser]cerberus478[/eluser]
That worked thanks. Is there a way to mark the thread solved?




Theme © iAndrew 2016 - Forum software by © MyBB