
Untitled
By: a guest on
Jul 15th, 2012 | syntax:
None | size: 0.87 KB | hits: 14 | expires: Never
How to loop through returned SQL results in Yii - nextRecord()
TOTAL
-----
999
ID |NAME
---|----
0 | Jon
1 | Bob
2 | Sarah
3 | Pete
//create the call to stored proc
$command=parent::$db->createCommand("exec sp_showUsers");
//run the query
$dataReader = $command->query();
//For the current object assign the row to a variable
while (($row = $dataReader->read()) !== false){
//if the row has a total column
if(isset($row['total'])){
$total = $row['total'];
}
}
//Test if there is another result
$usersExist = $dataReader->nextResult();
//$dataReader->next(); - REMOVED AS NOT NEEDED
if($usersExist){
$userTable = array();
$i = 0;
while (($userRow = $dataReader->read())!== false){
//add each row to a temporary array
$userTable[$i] = $userRow['id'];
$i++;
}
}
...