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

[eluser]daynie[/eluser]
Please anyone can help me with this code troubleshooting when i try to view my session it says
"Fatal error: Call to a member function num_rows() on a non-object in /home/domain/public_html/sub directory/application/models/applicationmodel.php on line 89"..

this my code below, thanks for your help guys [sorry bad eng Big Grin ]

=========================================================================================
{
$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;
}
=========================================================================================
#2

[eluser]Computerzworld[/eluser]
proper syntax is : num_rows not num_rows()...
#3

[eluser]daynie[/eluser]
thanks Computerzworld, but now the error message becomes

========================================================
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/applicationmodel.php
Line Number: 89
========================================================
#4

[eluser]Computerzworld[/eluser]
then there may be some problem in your query....you can check your existing query by writing $this->db->last_query() exactly after $this->db->get() and check it whether its correct or not....
#5

[eluser]daynie[/eluser]
sorry, i'm still newbie, should i write like this .. ?

=========================================================================================
{
$this->db->select(‘lang_code, lang_name’);
$this->db->from(‘languages’);
$langQuery = $this->db->get(); $this->db->last_query();
$languages = array();
if ($langQuery->num_rows() > 0)

=========================================================================================

or

=========================================================================================
{
$this->db->select(‘lang_code, lang_name’);
$this->db->from(‘languages’);
$langQuery = $this->db->get();
$langQuery = $this->db->last_query();
$languages = array();
if ($langQuery->num_rows() > 0)

=========================================================================================
#6

[eluser]TheFuzzy0ne[/eluser]
Are you extending the Model class and calling the parent model's constructor in your constructor?

Code:
class Applicationmodel extends Model { // Must extend the Model class.

    function Applicationmodel()
    {
        parent::Model(); // Must call this to initialize the class
    }

    ...
}
#7

[eluser]Colin Williams[/eluser]
@Computerzworld, actually it is a method, num_rows() and not a property.

To clarify, is "if ($langQuery->num_rows() > 0)" actually line number 89. Seems so, but just checking.
#8

[eluser]Colin Williams[/eluser]
@TheFuzzy0ne, he'd probably get an error before that line if $this->db was non-existent
#9

[eluser]daynie[/eluser]
okay thanks guys,
now my page session appear [with the A PHP Error was encountered, Severit ..bla bla .. Line Number: 89 on top] and 'language' button is blank.. Sad
#10

[eluser]TheFuzzy0ne[/eluser]
[quote author="Colin Williams" date="1234631651"]@TheFuzzy0ne, he'd probably get an error before that line if $this->db was non-existent[/quote]

You're totally right, of course. Just another classic case of too much blood in the caffeine stream.




Theme © iAndrew 2016 - Forum software by © MyBB