Export data in excel and word format in PHP Codeigniter framework

you may try this for excel and word export data
first you make controller this like this

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class Data extends CI_Controller
{
  public function index()
  {
     $this->load->view('data_page_view'); 
  }
  public function toExcel()
  {
     $this->load->view('spreadsheet_view');
  }
}
 
put a link from where you want to download in a view like this

<a href='data/toExcel'>Export Data</a>
 
and this may your view for excel data

    <?php         
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=exceldata.xls");
    header("Pragma: no-cache");
    header("Expires: 0");
    ?>
    <table border='1'>
      <tr>
        <td>ID</td>
        <td>First Name</td>
        <td>Last Name</td>
        <td>Important info</td>
      </tr>
      <tr>
        <td>Nadeem</td>
        <td>Ijaz</td>
        <td>Nothing really...</td>
      </tr>
    </table>
 
and this code for word data

    <?php         
    header("Content-Type: application/vnd.ms-word");
    header("Expires: 0");
    header("Cache-Control:  must-revalidate, post-check=0, pre-check=0");
    header("Content-disposition: attachment; filename=\"worddata.doc\"");
    ?>
    <table border='1'>
      <tr>
        <td>ID</td>
        <td>First Name</td>
        <td>Last Name</td>
        <td>Important info</td>
      </tr>
      <tr>
        <td>Nadeem</td>
        <td>Ijaz</td>
        <td>Nothing really...</td>
      </tr>
    </table> 

MySQL database : Save Data in Arabic urdu or other than english

If you want to save arabic, Urdu, or other than english language data just change collations type like

Change the database tables collations types to utf8_general_ci and also table fields collations change to utf8_general_ci.

Laravel using paginate with only selected columns?

Laravel query for pagination
$user = User::paginate(5,['id','name','username'.....]);

Featured Post

Assignemtn solution for CS61 spring 2020

Assignment solution CS601 S. No. Question Answer 1 Which type of topology is used in ...