0

I am trying to set permissions to users and when i put this in my database config code

public function hasPermission($key) {
    $group = $this->_db->get('groups', array('id', '=', $this->data()->group));
    print_r($group->first());
}

with the combination of this code that is in in my my home page

if($user->hasPermission('admin')) {
    echo '<p>You are an administrator!</p>';
}   

The problem I get occurs and says:

Undefined offset: 0 in C:\xampp\htdocs\Sites\ooplr\classes\DB.php on line 120

I then go and the code it has a problem with is

public function first() {
    return $this->results()[0];
}

Please Help!

ScottJShea
  • 7,041
  • 11
  • 44
  • 67
user3119898
  • 27
  • 1
  • 1
  • 5
  • possible duplicate of [mysql\_fetch\_array() expects parameter 1 to be resource, boolean given in select](http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given-in-select) – Michael Hampton Dec 25 '13 at 02:11

1 Answers1

0

That means you don't have any results, so result 0 doesn't exist.

I am guessing that $group = $this->_db->get('groups', array('id', '=', $this->data()->group)); is setting the results property that $this->results() returns. So, that query to the database must be failing and therefore not populating whatever $this->results() returns as an array. Rather than an array with data in it, you either have an empty array or something that isn't an array at all, and therefore no property 0, which would be item 1 in the array.

m59
  • 43,214
  • 14
  • 119
  • 136
  • so i have to find a the property that is in accordence to – user3119898 Dec 24 '13 at 17:47
  • @user3119898 it's basic debugging `var_dump` everything in the chain from your database query to that function and you'll see that you're not getting what you expect. Then you need to figure out why. Probably because your database query either fails or returns no data. – m59 Dec 24 '13 at 17:52