Welcome Guest, Not a member yet? Register   Sign In
too many rows breaking download
#1

[eluser]alberto24[/eluser]
Hi - I am having a problem with one of my customers - they have about 5,000 rows in the database and when I try to run the code to create a file (csv), in firefox it immediately goes to a blank white page and in IE i get a 500 error. customers with lesser amounts of rows still work fine.

Any ideas on how to fix this so it works? Here's my code:

Code:
function itemscsvdownload()
    {
        gateKeeper( 1 );    

        $this->load->model( 'item_model' );
        $objitemInfo = $this->item_model->getByitem( $this->session->userdata( 'user_id' ));

        {
        $this->load->helper('download');
        $this->db->where('customer_id', $this->session->userdata( 'user_id' ));
        $result = $this->db->get('itemdb');

        $name = 'items.csv';

        $data = '"item","iteminfo","iteminfo1"' . "\r\n";
        foreach ($result->result() as $thing)
        {
            $data .= chr(34) . $thing->item . chr(34). ",";
            $data .= chr(34) . $thing->iteminfo . chr(34). ",";
            $data .= chr(34) . $thing->iteminfo1 . chr(34). ",";            
        }
        force_download($name, $data);
    }
        }

I removed some of the other data bits just to make it clearer. Any help is very much appreciated.

Thanks!
#2

[eluser]pistolPete[/eluser]
Enable error displaying / logging to see what's going on.

It's probably a memory issue, try increasing memory_limit in your php.ini

Btw: Did you know there is a function csv_from_result() ?

See the user guide: user_guide/database/utilities.html
#3

[eluser]alberto24[/eluser]
thanks pistol - I upped the memory to 64mb and it seems to work now. and i will check out the function as well - appreciate the help
#4

[eluser]TheFuzzy0ne[/eluser]
It may benefit you more to avoid using result objects in this instance, and instead use the database result directly. I think that uses much less memory, since the resources don't actually contain the data. I might be wrong though.

I think that the fact that you're views are all buffered will be consuming a lot of RAM also.




Theme © iAndrew 2016 - Forum software by © MyBB