php - Undefined variable, why? -
i don't understand why variables $return , $id undefined...
error:
notice: undefined index: id in c:\inetpub\wwwroot\inc\classes\users.php on line 49 notice: undefined variable: return in c:\inetpub\wwwroot\inc\classes\users.php on line 49 code:
public static function getfollowers($id) { $query = db::query('select id_follower '.table_followers.' id_user = "'.db::escape($id).'"'); while($array = db::fetch_assoc($query)) { $return .= '<img style="margin-left: 2px;" id="img-round" src="'.users::useravatar($array['id']).'" width="40" height="40" />'; } return $return; } line 49:
$return .= '<img style="margin-left: 2px;" id="img-round" src="'.users::useravatar($array['id']).'" width="40" height="40" />'; thanks.
to address second issue, first initiate variable before concatenating onto it:
public static function getfollowers($id) { $return = ''; /* here */ $query = db::query('select id_follower '.table_followers.' id_user = "'.db::escape($id).'"'); while($array = db::fetch_assoc($query)) { $return .= '<img style="margin-left: 2px;" id="img-round" src="'.users::useravatar($array['id']).'" width="40" height="40" />'; /* return $return; -- move outside while() loop */ } return $return; /* moved here */ } to address first, $array has no key-pair id. verify exists before trying use it:
if ( isset( $array['id'] ) ) $return .= '<img style="margin-left: 2px;" id="img-round" src="'.users::useravatar($array['id']).'" width="40" height="40" />'; as mentioned in comments, you're trying access $array['id'] when mean accessing $array['id_follower']
Comments
Post a Comment