Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Generate CSV with 2 Tables using Codigniter

Tags: lead


I have Two tables in DB. One is Lead and other lead note.. Lead and Lead note have foreign key relationship.. I want to generate a CSV so its have One lead column then All the notes related to that Lead..

Here is what I need My current code is

$all_leads = '';
$name = 'leads-'.date('d-m-Y').'.csv';
$this->db->select("lead_id as Lead ID,business_name as Business,contact_name as First Name,contact_name_last as Last Name,work_email as Email,contact_email as Personal Email,work_number as Work Number,cell_no as Cell No,city as City,state as State,zip as Zip,date_added as Date Added,IF( label_type 0,'Important',' ') as Label, companies.company_name as company name");
$this->db->join('companies', ' =');
$leads = $this->db->get();
$num_rows = $leads->num_rows();

$all_leads= $this->dbutil->csv_from_result( $leads );
write_file( $this->file_path . '/'.$name,$all_leads );
$data = file_get_contents($this->file_path . '/'.$name);

force_download( $name, $data );
delete_files( $this->file_path . '/'.$name );`

Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered

This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Generate CSV with 2 Tables using Codigniter


Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription