I have the following code that pulls data off a mysql database and stores it in a 2D array ($rows). But after I print the contents with a foreach loop I just can't seem to be able to use that array again! Can't figure out how to reset it (printing it again just gives garbage)!
$result = $database->query('SELECT * FROM testtable ORDER BY timestp DESC;');
$rows = array(array());
while ( $tmp = $db->fetch_assoc( $result ) )
{
$rows[] = $tmp;
};
foreach ( $rows as $rows)
{
echo '<br />';
echo $rows['id']." --> ".$rows['timestp']." --- ".$rows['val'];
}
Using the array first time works for any operation, btw. Help needed!
I found this following bit of code but it doesn't seem to work as I wish:
function Array_Dimensional_Reset(&$arrRef) {
foreach ($arrRef as $key=>$val) {
if (is_array($val)) {
$this->Array_Dimensional_Reset($val);
reset($arrRef[$key]);
}
}
}
Thanks.