gh0st - 09 February 2010 06:13 PM
Hi.
@Phil—Thanks for the answer, I appreciate it. I’ll just use sizeof to find out the num_rows() on a query.
There’s another problem. When I try to run the this->Table->generate($Query_object_goes_here) using the MY_Model, you can’t use query.
There are several other instances where I need direct access to the query object, the problem is that MY_Model always returns an array, never an object.
If we look at Jamie Rumbelow’s MY_Model get_all() method:
/**
* Get all records in the database
*
* @return array
* @author Jamie Rumbelow
*/
public function get_all() {
return $this->db->get($this->table)
->result();
}
It runs the result() method, which then returns an array.
There are times when I need to use the object, not an array; for example—the Table->generate() needs an object, and it won’t work on an array.
Is there a way where I can grab the result object, without physically hacking Jamie’s code?
Thanks
You are getting a little confused here. We are talking about 3 different things:
$query: this is the usual name for the database object. Table library really does not want this!
$query->result(): This is an array of objects, this is what MY_Model returns.
$query->result_array(): This is an array of arrays (a multi-dimensional array) which works with Table in the exact same way as $query->result().
function generate($table_data = NULL)
{
// The table data can optionally be passed to this function
// either as a database result object or an array
if ( ! is_null($table_data))
{
if (is_object($table_data))
{
$this->_set_from_object($table_data);
}
elseif (is_array($table_data))
{
$set_heading = (count($this->heading) == 0 AND $this->auto_heading == FALSE) ? FALSE : TRUE;
$this->_set_from_array($table_data, $set_heading);
}
}
Should be fine. Try debugging a little. 