[eluser]Robert Wallis[/eluser]
Add this to the DB_result class, at the end of the class (but inside it) is fine if you want to use functionality like this:
Code:
$result = $this->db->query("SELECT * FROM bigtable");
foreach($result as $row) {
// ...
}
Here's the code to insert into DB_result:
Code:
/**
* Iterator implemented functions
* http://us2.php.net/manual/en/class.iterator.php
*/
/**
* Rewind the database back to the first record
*
* @return void
* @author Robert Wallis
*/
function rewind()
{
if ($this->result_id !== FALSE AND $this->num_rows() != 0) {
$this->_data_seek(0);
$this->valid = TRUE;
}
}
/**
* Return the current row record.
*
* @return object row_data
* @author Robert Wallis
*/
function current()
{
if ($this->current_row === -1)
$this->next();
return $this->row_data;
}
/**
* The current row number from the result
*
* @return int current_row
* @author Robert Wallis
*/
function key()
{
return $this->current_row;
}
/**
* Go to the next result.
*
* @return bool Is there a next result.
* @author Robert Wallis
*/
function next()
{
$this->row_data = $this->_fetch_object();
if ($this->row_data) {
$this->current_row++;
if (!$this->valid)
$this->valid = TRUE;
return true;
} else {
$this->valid = FALSE;
return FALSE;
}
}
/**
* Is the current_row really a record?
*
* @return bool
* @author Robert Wallis
*/
function valid()
{
return $this->valid;
}