Welcome Guest, Not a member yet? Register   Sign In
Export to excel
#9

(06-16-2021, 05:12 AM)Tajar_Dobro Wrote:
PHP Code:
public function search_expense($search=NULL){

 
$keyword $this->input->get('search',TRUE);
        
        
// pagination settings
        $total_rows $this->db->select('*')->from('expenses')->like("expense",$keyword)->get()->num_rows();
        $limit 15;
        $config["base_url"] = base_url("expenses/search");
        $config["total_rows"] = $total_rows;
        $config["per_page"] = $limit;

        $config['next_link'] = '→';
        $config['prev_link'] = '←'
        $config['full_tag_open'] = "<ul class='pagination justify-content-center'>";
        $config['full_tag_close'] = "</ul>"
        $config['num_tag_open'] = '<li class="page-item">';
        $config['num_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="page-item active"><a class="page-link">';
        $config['cur_tag_close'] = '</a></li>';
        $config['next_tag_open'] = '<li class="page-item">';
        $config['next_tagl_close'] = '</a></li>';
        $config['prev_tag_open'] = '<li class="page-item">';
        $config['prev_tagl_close'] = '</li>';
        $config['first_tag_open'] = "<li class='page-item disabled'>";
        $config['first_tagl_close'] = "</a></li>";
        $config['last_tag_open'] = '<li class="page-item">';
        $config['last_tagl_close'] = '</a></li>';
        $config['attributes'] = array('class' => 'page-link');

        $this->pagination->initialize($config);
        $header["links"] = $this->pagination->create_links();

        $start $this->uri->segment(3);
        $header['query'] = $this->db->select("*")
        ->from("expenses")
        ->like("title",$keyword)
        ->or_like("user",$keyword)
        ->or_like("amount",$keyword)
        ->limit($limit,$start)
        ->order_by('id','DESC')
        ->get()
        ->result_array();

        $this->load->view('expenses/index'$header);

  

paulkd
(06-14-2021, 12:35 AM)Tajar_Dobro Wrote: Well, I have the main query in the DB.
now I want only to export the return from the search. also, PHP excel does not work.
This code exports me all the values whereas I need only the result from the search

    //Expor to Excel
    public function export_csv(){ 
        
         $filename = 'expenses_'.date('Y-m-d').'.csv'
         header("Content-Description: File Transfer"); 
         header("Content-Disposition: attachment; filename=$filename"); 
         header("Content-Type: application/csv; ");
 
         $expenses_data = $this->expenses_model->export_expenses();

         $file = fopen('php://output''w');
 
         $header = array("Nr."
                        "Title"
                        "Date",
                        "Time",
                        "User",
                        "Amount",
                        ); 
         fputcsv($file$header);
         foreach ($expenses_data as $key=>$line){ 
             fputcsv($file,$line); 
         }
         fclose($file); 
         exit
    }
     

Can you show us the search code ?
Reply


Messages In This Thread
Export to excel - by Tajar_Dobro - 06-12-2021, 02:21 PM
RE: Export to excel - by InsiteFX - 06-12-2021, 08:57 PM
RE: Export to excel - by Tajar_Dobro - 06-13-2021, 02:36 AM
RE: Export to excel - by InsiteFX - 06-13-2021, 05:51 AM
RE: Export to excel - by demyr - 06-13-2021, 06:31 AM
RE: Export to excel - by Tajar_Dobro - 06-14-2021, 12:35 AM
RE: Export to excel - by paulkd - 06-16-2021, 05:12 AM
RE: Export to excel - by Tajar_Dobro - 06-18-2021, 04:42 AM
RE: Export to excel - by suvi - 06-16-2021, 03:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB