I'm currently working on a Zend 2 project and I have some problems with a foreach within another foreach. Here my code :
foreach($test as $one){
echo $one->name;
foreach($place as $param){
echo $param['name_place'];
}
unset($param);
}
I get the following error :
Fatal error: Uncaught exception 'Zend\Db\Adapter\Exception\RuntimeException' with message
'This result is a forward only result set, calling rewind() after moving forward is not supported' in
/vendor/zendframework/zendframework/library/Zend/Db/Adapter/Driver/Pdo/Result.php:154
Stack trace: #0 /module/Check/view/check/check/choix-niveau.phtml(25):
Zend\Db\Adapter\Driver\Pdo\Result->rewind() #1 /vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php(506):
include('/var/www/vhosts...') #2 /vendor/zendframework/zendframework/library/Zend/View/View.php(205):
Zend\View\Renderer\PhpRenderer->render(Object(Zend\View\Model\ViewModel))
#3 /vendor/zendframework/zendframework/library/Zend/Mvc/View/Http/DefaultRenderingStrategy.php(103):
Zend\View\View->render(Object(Zend\View\Model\ViewModel)) #4 [internal function]:
Zend\Mvc\View\Http\DefaultRenderingStrategy->render( in /vendor/zendframework/zendframework/library/Zend/Db/Adapter/Driver/Pdo/Result.php on line 154
And the models from the 2 foreachs :
public function getAllPlace()
{
$select = new Select();
$select->from('place')
->join('level', 'level.id = place.id_level', array('nom'))
->order('level.id');
$statement = $this->tableGateway->getSql()->prepareStatementForSqlObject($select);
$resultSet = $statement->execute();
$resultSet->buffer();
return $resultSet;
}
And the second model
public function getAllTry()
{
$select = new Select();
$select->from('try')
->order('id');
$resultSet = $this->tableGateway->selectwith($select);
$resultSet->buffer();
return $resultSet;
}
The problem is coming from $place as $param
because if the code is $place as $place
there is no error. But I need to change the name variable to unset him.
Thanks per advance!
PokeRwOw
EDIT :
In the array $test there are 3 values and in the array $place there are 2 values. So the result after launch :
- First value of $test
- First value of $place
- Second value of $place
-Second value of $test
And this is here where It's finish. So certainly It is coming for the cursor of the second foreach or something like this ?
If I make the two foreach separately and not imbrique Its working...