In my model i have the following code:
$this->db->from($this->table_name);
$this->db->where('user_id', $userid);
$this->db->where('role_key', $key);
$query = $this->db->get();
return $query->result();
Then in my view i have the following
$ci =& get_instance();
$thistest = $ci->model->functionname($row->id,$role->key);
if($thistest > 0){ echo 'valid'; }
I know im not meant to be calling stuff from a view, im just running a test,开发者_如何学编程 but its not working, and im cant seem to figure out why .... its just echoing valid a whole bunch of times when according to the database, its only meant to echo it twice.
I don't know what you are trying to do but I'm pretty sure that this code won't work. if what you are trying is return some data from your a table you can do something like that...
$query = $this->db->get('entries'); //so here you get data from the table called entries
$entries = array(); //here you create an array called entries(I use the same name //because it's more or less the same data)
//here is where we retrieve all data and insert them in the array we previously created
//if we don't want some data from our table we can omit them...
foreach ($query->result_array() as $entry) {
$entries[] = array('title' => $entry['title'],
'body' => $entry['body'],
'author' => $entry['author'],
'date_time' => $entry['date_time'],
'id' => $entry['id']
);
}
return $entries; //finally we return the array
now you can call this array somewhere in your controller and load it in a view...in the code you displayed several queries was displayed without any actual connection with each other and finally you return something called $this->db->get();
without including any table name into it...
use that as reference and good luck
http://codeigniter.com/user_guide/general/models.html
精彩评论