⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

After callback_insert how to export the inserted rows to excel ??



vissuviswanath
  • profile picture
  • Member

Posted 27 February 2015 - 10:04 AM

Hi,

When user click on the ADD  button i have been taking the count entered by the user and inserting  multiple records in a table using callback_insert function. After insertion we need to generate the excel of the latest inserted rows only. Please help in this....

 

public function coupons()
{
        $crud = new grocery_CRUD();
  $crud->set_table('normal_coupon_codes');
$crud->columns('coupon_code','date','coupon_percentage','User_name');
$crud->display_as('Coupon Code','Date Created','Coupon Percentage','User Created'); 
$crud->set_subject('Normal Coupons');
 $crud->order_by('date','desc');
//$crud->required_fields('username','email','password','status','register_date','mobile');
$crud->unset_edit();
$crud->unset_delete();
$crud->add_fields('coupon_percentage','number');
$crud->display_as('coupon_percentage','Percentage');
$crud->display_as('number','Number of Coupons');
 $crud->field_type('coupon_percentage','dropdown',
            array('10' => '10', '25' => '25','50' => '50', '100' => '100'));
  $crud->callback_insert(array($this, 'log_user_after_insert'));
 
$crud->required_fields('percentage','number');
 
$output = $crud->render();
 
$this->_example_output($output);
$this->load->view('footer');
}

 

 

function log_user_after_insert($post_array)
{
  for($x=0;$x<$post_array['number'];$x++){
 
$random = "";
        srand((double) microtime() * 1000000); 
        $length = 15;
        $data   = "AbcDE123IJKLMN67QRSTUVWXYZ";
        $data  .= "aBCdefghijklmn123opq45rs67tuv89wxyz";
        $data  .= "FGH45OP89";
        
        for ($i = 0; $i < $length; $i++) {
            $random .= substr($data, (rand() % (strlen($data))), 1);
      }
       $randomval = $random;
     $this->db->set('coupon_percentage', $post_array['coupon_percentage']);
$this->db->set('user_name', $this->session->userdata['admin_username']);
  $this->db->set('coupon_code', $randomval);
$this->db->set('date', date("Y-m-d H:i:s"));
$this->db->insert('coupon_codes');
 
}
  
   return true;
}