Welcome Guest, Not a member yet? Register   Sign In
Undefined offset: 0 and Trying to get property of non-object
#1
Bug 

my page shows 2 php errors (curiously only on OSX and not Windows 10 or Android):

A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 0
Filename: controllers/Dating.php
Line Number: 1822
Backtrace:
File: /home/xxx/public_html/application/controllers/Dating.php
Line: 1822
Function: _error_handler
File: /home/xxx/public_html/index.php
Line: 292
Function: require_once

A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: controllers/Dating.php
Line Number: 1822
Backtrace:
File: /home/xxx/public_html/application/controllers/Dating.php
Line: 1822
Function: _error_handler
File: /home/xxx/public_html/index.php
Line: 292
Function: require_once

Line 1822 has:

Code:
$str = "select * from users WHERE id!='".$this->session->userdata('user_id')."' AND country='".$query1[0]->country_name."' AND image_name!='' AND IS_ONLINE!='0' ORDER BY IS_ONLINE DESC LIMIT 0,6 ";

and line 1818:

Code:
$query1=$this->db->query($str1)->result();
Reply
#2

(11-05-2015, 03:03 PM)ronaldv Wrote: my page shows 2 php errors (curiously only on OSX and not Windows 10 or Android):

A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 0
Filename: controllers/Dating.php
Line Number: 1822
Backtrace:
File: /home/xxx/public_html/application/controllers/Dating.php
Line: 1822
Function: _error_handler
File: /home/xxx/public_html/index.php
Line: 292
Function: require_once

A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: controllers/Dating.php
Line Number: 1822
Backtrace:
File: /home/xxx/public_html/application/controllers/Dating.php
Line: 1822
Function: _error_handler
File: /home/xxx/public_html/index.php
Line: 292
Function: require_once

Line 1822 has:

Code:
$str = "select * from users WHERE id!='".$this->session->userdata('user_id')."' AND country='".$query1[0]->country_name."' AND image_name!='' AND IS_ONLINE!='0' ORDER BY IS_ONLINE DESC LIMIT 0,6 ";

and line 1818:

Code:
$query1=$this->db->query($str1)->result();

You should use var_dump($query1) after line 1818 to check it has any row return.
Reply
#3

(11-05-2015, 08:39 PM)pdthinh Wrote: You should use var_dump($query1) after line 1818 to check it has any row return.

Do you mean using var_dump() for debugging?

I just solved the issue in this way:

Code:
$result1 = $this->db->query($str1)->result();
    if ( count($result1) == 0)
    {
        $country = 'xx';
    }
    else
    {
        $country = $result1[0]->country_name;
    }
$str = "select * from users WHERE id!='".$this->session->userdata('user_id')."' AND country='".$country."' AND image_name!='' AND IS_ONLINE!='0' ORDER BY IS_ONLINE DESC LIMIT 0,6 ";
Reply
#4

Quote:Do you mean using var_dump() for debugging?
Yes, I mean that because the errors show that $query1 doesn't have any row returned. Sorry for the confusion.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB