Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

foreach() to retrieve records only working once #40

Open
talkingpixels opened this issue Mar 26, 2019 · 1 comment
Open

foreach() to retrieve records only working once #40

talkingpixels opened this issue Mar 26, 2019 · 1 comment

Comments

@talkingpixels
Copy link

talkingpixels commented Mar 26, 2019

Hi, I'm trying to loop through an array of ids and return some corresponding records, something like this...

foreach (['recHg30ki6MeYP40s','recvtmtL2umW0fDzT'] as $attr){
	$item = $items->from('rows')->where('id', '=', $attr)->get();
	print_r($item);
}

It outputs the array correctly in the first loop, but second (or more) loop return nothing and the following warning:

Warning:  array_filter() expects parameter 1 to be array, object given in /Users/.../vendor/nahid/jsonq/src/JsonQueriable.php on line 393

Any thoughts? Could it be something to do with pointers?

@marccreus
Copy link

When you use "from" the pointer moves to (in your case) "rows" scope. So when in the second loop you try to do "from" again it's searching for "rows" inside previous "rows". You should use:
$items->reset()->from('rows')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants