1

Hi I am just beginning to use redbeans ORM. I followed the docs and tried doing a query like this

$thebean=R::find("users","id>2");

and then I loop through like:-

foreach($thebean as $bean){
echo $bean->username;
}

However I find that if the even if the users table contains more than 100 data, the above query only fetches the last data . for eg: if I have users 1 to 100. I only get the user with id=100. Can somebody please tell me what I might be doing wrong.

Rasmus
  • 8,248
  • 12
  • 48
  • 72

4 Answers4

3

Could it be that your syntax is not correct? I have no experience with Redbean, but you might want to do something like this:

$users = R::find('users', 'id > ?', array('2'));
var_dump($users);

Either way, what is your result when you do the following? Does it return all your users or just one?

$users = R::find('users');
var_dump($users);
vindia
  • 1,678
  • 10
  • 14
2

You have to use "findAll" on the query. So for example:

$thebean = R::findAll('users', 'id > 2' array('id' => 2));

then you can do your standard foreach:

foreach ($thebean as $key => $bean) {

 echo $bean->username;

} 
Eddie
  • 146
  • 2
  • 7
2

Seems that it was a problem with the id field. Solved it using tableformatter option.

Rasmus
  • 8,248
  • 12
  • 48
  • 72
1

Could be a problem on the type of field? Are you tried with: $thebean=R::find("users","id>'2'"); ?

Galled
  • 4,146
  • 2
  • 28
  • 41