Question: The normal `result()` method described in the documentation appears to load all records immediately. My application needs to load about 30,000 rows, and one at a time, submit them to a third-party search index API. Obviously loading everything into memory at once doesn't work well (errors out because of too much memory).

So my question is, how can I achieve the effect of the conventional MySQLi API method, in which you load one row at a time in a loop?

Answer: 
Here is something you can do.

```
while ($row = $result->_fetch_object()) {
  $data = array(
    'id'         => $row->id
    'some_value' => $row->some_field_name
  );
  // send row data to whatever api
  $this->send_data_to_api($data);
}

```

This will get one row at the time. Check the CodeIgniter source code, and you will see that they will do this when you execute the result() method.
Well, there'se the **[row()](http://ellislab.com/codeigniter/user-guide/database/results.html)** method, which returns just one row as an object, or the **row\_array()** method, which does the same but returns an array (of course).

So you could do something like

```
$sql = "SELECT * FROM yourtable";
$resultSet = $this->db->query($sql);
$total = $resultSet->num_rows();

for($i=0;$i<$total;$i++) {
  $row = $resultSet->row_array($i);
}

```

This fetches in a loop each row from the whole result set.  

Which is about the same as fetching everyting and looping over the `$this->db->query($sql)->result()` method calls I believe. 

If you want a row at a time either you make 30.000 calls, or you select all the results and fetch them one at a time or you fetch all and walk over the array. I can't see any way out now.