While loop in foreach loop not looping correctly

Posted by tominated on Stack Overflow See other posts from Stack Overflow or by tominated
Published on 2010-05-09T23:23:41Z Indexed on 2010/05/09 23:28 UTC
Read the original article Hit count: 231

Filed under:
|

I'm trying to make a very basic php ORM as for a school project. I have got almost everything working, but I'm trying to map results to an array. Here's a snippet of code to hopefully assist my explanation.

$results = array();

foreach($this->columns as $column){

    $current = array();

    while($row = mysql_fetch_array($this->results)){
        $current[] = $row[$column];
        print_r($current);
        echo '<br><br>';
    }

    $results[$column] = $current;

}

print_r($results);

return mysql_fetch_array($this->results);

This works, but the while loop only works on the first column. The print_r($results); shows the following:

Array ( [testID] => Array ( [0] => 1 [1] => 2 ) [testName] => Array ( ) [testData] => Array ( ) )

Can anybody shed some light? Thanks in advance!

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql