Welcome Guest, Not a member yet? Register   Sign In
[Need help] Fatal error: Call to a member function num_rows() on a non-object
#11

[eluser]TheFuzzy0ne[/eluser]
Any chance of seeing the entire model?
#12

[eluser]daynie[/eluser]
here the entire code,

=============================================================================================================
<?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;
}
}

?>
=============================================================================================================
#13

[eluser]TheFuzzy0ne[/eluser]
I don't understand the problem, but as a desperate attempt to get things working, please try this function:
Code:
function getLanguages()
{
    $this->db->select('lang_code, lang_name');
    $langQuery = $this->db->get('languages');
    $languages = array();
    if ($langQuery->num_rows() > 0)
    {
        foreach ($langQuery->result_array() as $langRow)
        {
            $languages[] = $langRow;
        }
    }
    return $languages;
}

All I've done is omitted the from() call, and put the table name in the get() call.

EDIT: Oh, and added brackets to the num_rows() call.
#14

[eluser]TheFuzzy0ne[/eluser]
After looking at your function in a little more detail, I can't see the need for the foreach loop.

This function should work identically.
Code:
function getLanguages()
{
    $this->db->select('lang_code, lang_name');
    $langQuery = $this->db->get('languages');

    return ($langQuery->num_rows() > 0) ? $langQuery->result_array() : array();
}
#15

[eluser]daynie[/eluser]
doesnt work Sad
is there any possibility make some changes in database?
#16

[eluser]TheFuzzy0ne[/eluser]
That's very strange indeed. How are you loading your model, and also, have you extended the CI_Model class with your own custom library (MY_Model)?

I wouldn't have thought the problem is with the database, as you'd get a different kind of error. It's almost as if there is a problem with the CI_Result class. That's what the call to get() should be returning, and it clearly isn't, as num_rows() isn't available.
#17

[eluser]daynie[/eluser]
thanks fuzzy it works, after i make some changes in code permission access then write down ur code. anyway Thanks for ur help guys
#18

[eluser]TheFuzzy0ne[/eluser]
Glad you got it working. Smile
#19

[eluser]Unknown[/eluser]
hi fuzzyOne ,i read your post but i dont check this 100 %

i have this erorr

“Fatal error: Call to a member function num_rows() in application/models/applicationmodel.php on line 89”..


please can you change me that this work and send back ?
here the full text form applicationmodel.php

############################################################
<?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;
}
}

?>
#20

[eluser]starfish76[/eluser]
Hi i keep getting this error message

Fatal error: Call to a member function num_rows() on a non-object in /home/mafiamob/public_html/home/mafiaspace/application/models/applicationmodel.php on line 90

can someone correct this code for me please? as i've tried for quite awhile now

-------

<?php

/**
* User Model
*
*
* @copyright Copyright © 2008 [x-MoBiLe] Nulled
* @license
* @since 1/2/2008
*/
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');
echo "<pre>";print_r($appQuery);echo" </pre>";
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;
}
}

?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB