Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP prepared statement - reset row pointer
    primarykey
    data
    text
    <p>I have the below code, which the comments should clearly explain. I want to query a file for given information, and then once the results are returned, add a field onto the resulting array. Then, access the resulting array later in my program.</p> <p>The problem with the code below is, i think the array is at the last record the second time i attempt to loop... and reset($stmt1) fails because $stmt1 is "not an array object"...</p> <pre><code>&lt;?php $sql1 = "SELECT dpdpt, SUM(dpbir) FROM dwhlib.dwdptstr WHERE dpdpt &lt; '312' GROUP BY dpdpt "; //Setup connection $conn_resource = db2_connect ( "*LOCAL", "", "" ); //Verify connection successful if (! $conn_resource) { echo "Connection failed. SQL Err:"; echo db2_conn_error (); echo "&lt;br/&gt;"; echo db2_conn_errormsg (); exit (); } //Prepare the stmt $stmt1 = db2_prepare ( $conn_resource, $sql1 ); //Execute the prepared statement if (! db2_execute ( $stmt1 )) { echo 'The db2 execute failed. '; echo 'SQLSTATE value: ' . db2_stmt_error (); echo ' Message: ' . db2_stmt_errormsg (); exit (); } //Loop through all rows, adding a third field while ( $row1 = &amp;db2_fetch_array ( $stmt1 ) ) { $row1[2] = "TEST"; } //Reset stmt or array back to first record //?? //Print results echo "&lt;table border=1&gt;"; while ( $row = db2_fetch_array ( $stmt1 ) ) { echo "&lt;tr&gt;"; echo " &lt;td&gt;" . $row[0] . "&lt;/td&gt;"; echo " &lt;td&gt;" . $row[1] . "&lt;/td&gt;"; echo " &lt;td&gt;" . $row[2] . "&lt;/td&gt;"; echo "&lt;/tr&gt;"; } echo "&lt;/table&gt;"; ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload