bazz Posted September 8, 2008 Share Posted September 8, 2008 Hi Guys, Wondering if anyone can help me with this? Here is the error message I get; Fatal error: Call to a member function num_rows() on a non-object And the line of code causing the error if ($langQuery->num_rows() > 0) Can you see anything wrong? thanks in advance bazz Link to comment https://forums.phpfreaks.com/topic/123262-fatal-error-call-to-a-member-function-num_rows-on-a-non-object/ Share on other sites More sharing options...
discomatt Posted September 8, 2008 Share Posted September 8, 2008 Yes. $langQuery has not been defined as an object. Link to comment https://forums.phpfreaks.com/topic/123262-fatal-error-call-to-a-member-function-num_rows-on-a-non-object/#findComment-636555 Share on other sites More sharing options...
bazz Posted September 8, 2008 Author Share Posted September 8, 2008 Thanks for your reply discomatt. How should it read? i'm sorry for being a proper noob *but I am lol* Regards bazz Link to comment https://forums.phpfreaks.com/topic/123262-fatal-error-call-to-a-member-function-num_rows-on-a-non-object/#findComment-636561 Share on other sites More sharing options...
discomatt Posted September 8, 2008 Share Posted September 8, 2008 That's hard to say, at some point you should be defining it as an object using $langQuery = new someClassName; Link to comment https://forums.phpfreaks.com/topic/123262-fatal-error-call-to-a-member-function-num_rows-on-a-non-object/#findComment-636564 Share on other sites More sharing options...
bazz Posted September 8, 2008 Author Share Posted September 8, 2008 Here is the entire page <?php class Applicationmodel extends Model { //Constructor function Applicationmodel() { parent::Model(); } function getApplications($onlyBasic = false) { if ($onlyBasic == true) $appQuery = $this->db->query('SELECT * FROM applications WHERE user_id=0'); else $appQuery = $this->db->query('SELECT * FROM applications'); if ($appQuery->num_rows() > 0) { $applications = array(); foreach ($appQuery->result_array() as $appRow) { $applications[$appRow['application_id']] = $appRow; } return $applications; } else return false; } function getUserApplications() { $this->db->select('application_ids'); $this->db->where('user_id', $this->session->userdata('user_id')); $this->db->limit(1, 0); $userAppQuery = $this->db->get('users_applications'); if ($userAppQuery->num_rows() > 0) { $userAppRow = $userAppQuery->result_array(); $appQuery = $this->db->query('SELECT * FROM applications WHERE application_id IN (' . $userAppRow[0]['application_ids'] . ')'); if ($appQuery->num_rows() > 0) { $applications = array(); foreach ($appQuery->result_array() as $appRow) { $applications[$appRow['application_id']] = $appRow; } return $applications; } else return false; } else return false; } function isApplication($appName) { $this->db->where('application_name', $appName); $this->db->limit(1, 0); $appQuery = $this->db->get('applications'); if ($appQuery->num_rows() > 0) { $appRow = $appQuery->result_array(); return $appRow[0]['application_id']; } else return false; } function isUserCanAccessTheApplication($applicationId) { $this->db->select('application_ids'); $this->db->where('user_id', $this->session->userdata('user_id')); $this->db->limit(1, 0); $userAppQuery = $this->db->get('users_applications'); if ($userAppQuery->num_rows() > 0) { $userAppRow = $userAppQuery->result_array(); $userAppArray = explode(',', $userAppRow[0]['application_ids']); if (array_search($applicationId, $userAppArray) === false) return false; else return true; } else return false; } function getLanguages() { $this->db->select('lang_code, lang_name'); $this->db->from('languages'); $langQuery = $this->db->get(); $languages = array(); if ($langQuery->num_rows() > 0) { foreach ($langQuery->result_array() as $langRow) { $languages[] = $langRow; } } return $languages; } } ?> Link to comment https://forums.phpfreaks.com/topic/123262-fatal-error-call-to-a-member-function-num_rows-on-a-non-object/#findComment-636575 Share on other sites More sharing options...
discomatt Posted September 8, 2008 Share Posted September 8, 2008 Somewhere in your Model class ( not listed here ) there is a var called $db that is supposed to be filled with what looks to be a singleton DB class. I'm leaning to believe this is not your code, and you're trying to play with things a little beyond your current PHP knowledge. Please correct me if I'm wrong. Link to comment https://forums.phpfreaks.com/topic/123262-fatal-error-call-to-a-member-function-num_rows-on-a-non-object/#findComment-636640 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.