Tuesday, 13 August 2013

Array fills only with latest value

Array fills only with latest value

I have that weird problem.
Array inside while loop (in my case $smt), does not want to fill up with
all the 30 values (there are 30 rows returned by my testing query). It
contains only the latest value. I checked the loop and it is okay. It does
30 repeats, and num_rows also returns 30. It happens only when i try to
fill array which uses a key, for example $array[$key]. For example
printing inside the loop and using arrays without key work like they
should.
Maybe i am missing something, but right now i cannot find the problem.
CODE:
if($res = $con->prepare($query)) {
call_user_func_array(array($res,'bind_param'),$bind);
if($res->execute()) {
$res -> bind_result($iStopID,$iDate,$iTime,$iOd,$iDo,$iType);
while ($res -> fetch()) {
$smt['$iDate']=$iStopID;
}
//test
print_r($smt['$iDate']);
} else error($con->error);
$res -> close();
} else error($con->error);

No comments:

Post a Comment