Skip to content
Advertisement

Codeigniter loop to chunk query only ever gets the first chunk of rows?

I’m trying to get a large amount of data by grabbing it in chunks from the database and writing it to CSV. For some reason the code below is only writing the first chunk (2000 rows) to CSV. I have my $chunk and $limit variables writing to a text file, and those are going through the loop and writing out the correct values. So why isn’t $result=$this->db->get(‘tblProgram’, $chunk, $offset)->result_array(); grabbing the next chunks?

Can you not run $this->db->get(‘tblProgram’, $chunk, $offset)->result_array(); multiple times with different offsets? How else would I loop through the results?

I can confirm that I have more than 200k rows returned from the query, and that if I set chunk to something different, I’m still only getting the first chunk returned.

JavaScript

Advertisement

Answer

https://github.com/bcit-ci/CodeIgniter/blob/develop/system/database/DB_query_builder.php

Looks like calling the get method resets your model:

JavaScript

I’d imagine this is the case of any version of ci.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement