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.
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"...
<?php $sql1 = "SELECT dpdpt, SUM(dpbir) FROM dwhlib.dwdptstr WHERE dpdpt < '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 "<br/>"; 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 = &db2_fetch_array ( $stmt1 ) ) { $row1[2] = "TEST"; } //Reset stmt or array back to first record //?? //Print results echo "<table border=1>"; while ( $row = db2_fetch_array ( $stmt1 ) ) { echo "<tr>"; echo " <td>" . $row[0] . "</td>"; echo " <td>" . $row[1] . "</td>"; echo " <td>" . $row[2] . "</td>"; echo "</tr>"; } echo "</table>"; ?>