zend framework2 - Cannot query a second result set without looping through the first result set -


i having issue zf2 trying use table gateways , getting result sets:

i trying query 2 result sets (from 2 different tables/two different gateways) , send them view iterated through , placed on screen.

(simplified example):

function viewaction() {     $table1 = $this->getservicelocator()->get('model\table\table1');     $table2 = $this->getservicelocator()->get('model\table\table2');      return new viewmodel([         'table1' => $table1->fetchall(),         'table2' => $table2->fetchall()     ]); } 

with model\table\table1 , model\table\table2 having fetch all:

public function fetchall() {     return $this->tablegateway->select(); } 

then in view:

... <?php foreach($table1 $row) {     echo "<tr><td>{$row['col1']}</td><td>{$row['col2']}</td></tr>"; } ?> ... <?php foreach($table2 $row) {     echo "<tr><td>{$row['col1']}</td><td>{$row['col2']}</td></tr>"; } ?> ... 

the problem is, $table1 have no data when looping. however, if instead (in controller, instead of passing result set view, passing $results1 , $results2 view):

$fetchall = $table1->fetchall(); $results1 = []; foreach($fetchall $row) {     $results1[] = $row; } $fetchall = $table2->fetchall(); $results2 = []; foreach($fetchall $row) {     $results2[] = $row; } 

then works fine. don't want have loop through same set of data twice. so why zf2 prevent me using 2 different resultsets before data in resultset has been accessed?

since querying different record sets 1 after other, database still waiting action take place on first query. i have 1 action record set @ time.

there first solution presented in question, record set , loop through rows available before trying query again. frees record set have data.

the second solution (the 1 have adapted), enable multiple active record sets (mars) database connection.

i able adding mars_connection=yes dsn connection string mssql.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -