HOW TO EXPORT THE CSV FILE BETWEEN TWO DATE IN CODEIGNITER 4
CodeIgniter is an Application Development Framework - a toolkit - for people who build web sites using PHP.
Its goal is to enable you to develop projects much faster than you could if you were writing code from scratch, by providing a rich set of libraries for commonly needed tasks, as well as a simple interface and logical structure to access these libraries. CodeIgniter lets you creatively focus on your project by minimizing the amount of code needed for a given task.
CSV file is been used for data import, export, and generating a report between two date.
If you have huge data available in the MySQL database and you only require a specific date range data but the file contains all records and you need it on your own.
In this tutorial, I show how you can export MySQL database data in CSV format by date range with PHP. I am using jQuery UI for datepicker.
In Controller
//Getting the vlaue from View Page using Post
$from_date = $this->request->getPost('from_date');
$to_date = $this->request->getPost('to_date');
// Pass the vlaue in Model
$var = ModelName::Function Name Of Model Name ('TableName',$from_date,$to_date);
// file creation to Generate CSV
//
In Model
// Define here function
Public static function //Function Name of Controller //($table,$from_date='',$to_date)
{
//DB Connect
//Using Builder
$builder = $db->table($table)
//Select Query
Select('*')
//Where Condition
//Here month is the Table Column name // $from_date & $to_date - getting from Controller
->where('month BETWEEN "'. date('Y-m-d', strtotime($from_date)). '" and "'. date('Y-m-d', strtotime($to_date)).'"')
->get()->getResultArray();
}
Comments
Post a Comment