CodeIgniter Forums
Num_rows Error - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Num_rows Error (/thread-25184.html)



Num_rows Error - El Forum - 12-03-2009

[eluser]Arasoi[/eluser]
Ok folks, I have poked around for a bit know and can not seem to find a post helping me with my issue. Now I know it is something retarded I have done but baring that in mind it is what also makes me unable to see it Smile

I get this error :
Code:
Fatal error: Call to a member function num_rows() on a non-object

From this code :
Code:
function con_getfieldchecks($Start,$PageSize,$EID = NULL)
    {
        $this->load->database('default', TRUE);

        if($EID == NULL){
        // Load the total number of rows in the table
            $this->db->select();
            $query = $this->db->get('fc_AddressRequests');
            $output['totalCount'] = $query->num_rows();
        // now retrive just the first page of data from that table
            $this->db->select();
            $this->db->where('A.rownum BETWEEN ('. $Start .') AND ('. $Start .'+'. $PageSize .' )');
            $query = $this->db->get('(SELECT row_number() OVER (ORDER BY RequestDate) AS rownum, * FROM   fc_AddressRequests_View) AS A');
            $output['records'] = $query->result_array();
        }else{
        // Load the total number of rows in the table matching the EID
            $this->db->select();
            $this->db->where('EID', $EID);
            $query = $this->db->get('fc_AddressRequests');
            $output['totalCount'] = $query->num_rows();
        // now retrive just the first page of data from that table matching the EID    
            $this->db->where('A.rownum BETWEEN ('. $Start .') AND ('. $Start .'+'. $PageSize .' )');
            $this->db->where('EID', $EID);
            $query = $this->db->get('(SELECT row_number() OVER (ORDER BY RequestDate) AS rownum, * FROM   fc_AddressRequests_View) AS A');
            $output['records'] = $query->result_array();
        }
        // Convert the array into JSON format and return it
        return json_encode($output);

    }


If I comment out the
Code:
$output['totalCount'] = $query->num_rows();
all works fine. but I do need the total rows returned in order for paging to work right on the tables I use. Big thanks from the start to all the help Smile


Num_rows Error - El Forum - 12-03-2009

[eluser]clip[/eluser]
Would start with trying this:
Code:
$this->db->select();
Try removing both calls to this method all together or change it to:
Code:
$this->db->select('*');
or use:
Code:
$this->db->count_all_results('table_name');



Num_rows Error - El Forum - 12-03-2009

[eluser]Arasoi[/eluser]
Found it sort of.

I removed the:
Code:
$this->db->select();

Per your suggestion and it did not work. then I noticed a slight error on my part to fix that should not have mattered but seems it did.

I changed the table name from :
Code:
$query = $this->db->get('fc_AddressRequests');
To:
Code:
$query = $this->db->get('fc_AddressRequests_View');

And all worked well, even though the table that the view is built from is the same name minus the "_View" bit. Either way thank you for the help it solved my dilemma if in a round about way. Big Grin