So I have a web app that I'm trying to create where I have to use odbc_exec to gather the results of two different queries and then create a JSON file with combined info from the two queries.
Example below (connection and query omitted)...
$result = odbc_exec($c, $q);
$result1 = odbc_exec($c, $q1);
$resultRows = array();
$response = array();
while($row = odbc_fetch_array($result)) {
$tempResult = $result1;
$value = "0";
$other = $row['FIELD'];
while($row1 = odbc_fetch_array($tempResult)) {
if($row['FIELD'] == $row1 ['FIELD']) {
$value = $row1['FIELD'];
}
}
if($value != "0") {
$resultRows[] = array('FIELD'=>$value, 'OTHER'=>$other);
}
}
$response['data'] = $resultRows;
$fp = fopen('somefile.json', 'w');
fwrite($fp, json_encode($response));
fclose($fp);
The problem with this is that it stops going into the nested while loop after the first loop through. I know that odbc_fetch_array removes the data from the results set which is why I attempted to create a reference to the result set that resets after each big loop, but that still doesn't resolve my problem.
Any info would be extremely helpful! Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire