General |  Social Media |  Miscellaneous
Login | Register
srcraft blog logo
  • Business
  • News
  • Shopping
  • Travel
  • Disease
  • Pets
  • Life
  • Health
  • Technology
  • Category
  • Contact Us
Latest Blog : 
☛ Who can be called a true monk ? ☛ God arranges everything ☛ Faith in god ☛ What is a Rotary Encoder? How does it work? ☛ Things to Know About PLC and SCADA ☛ According to Ramayana, why do women wear jewelry? ☛ After registering an FIR, can I not apply for a government job ☛ Daughter: A angel of his father ☛ How VOIP Phone System is Useful For your Business? ☛ test 
Home > Innovation & Technology > Codeigniter

How to find the previous month records in Codeigniter


How to find the previous month records in Codeigniter

This is easy way to finding last month records in codeigniter. For this, We will use three steps in CodeIgniter framework PHP.

 1. Create controler ie total_row.php

Path: CodeIgniter\application\controllers\ total_row.php

 2. Create Model ie record_fetch.php

Path: CodeIgniter\application\models\record_fetch.php

 3. Create View ie view_total_row.php

PAth: CodeIgniter\application\views\view_total_row.php

 

Create controlers: total_row.php

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Total_row extends CI_Controller {

            public function __construct()

            {

                        parent::__construct();

                        //calling model

                        $this->load->model("record_fetch");

            }

            public function index()

            {

            $this->data['fetchTotalRecords'] = $this->record_fetch->fetchRecord();    

            $this->load->view("view_total_row", $this->data);

            }

}

?>

 

Create models: record_fetch.php

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

            class Record_fetch extends CI_Model {

            function __construct()

            {

            //call model constructor

            parent::__construct();

            }

           

            function fetchRecord()

            {

            date_default_timezone_set('Asia/Kolkata');

            $first_date = date('Y-m-d', strtotime('first day of last month'));

            $last_date = date('Y-m-d', strtotime('last day of last month'));

            $this->db->select('*');

            $this->db->from('tableName');

            $this->db->where('columnName BETWEEN "'.$first_date.'" AND "'.$last_date.'" ');

            $query = $this->db->get();

            return $query->result();

            }

            }

?>

 

Create models: view_total_row.php

<!DOCTYPE html>

<html>

<body>

<table> 
<thead> 
<th>CustomerName</th> 
<th>CustomerLocation</th> 
</thead> 
<tbody> 
<?php 
foreach($fetchTotalRecords as $rowFound) 
{ 
$custName = $rowFound->cName;

$custLocation = $rowFound->cLocation;. 
echo "<tr> 
<td>$custName</td> 
<td>$custLocation</td>  
</tr>"; 
} 
?> 
</tbody> 
</table> 

</body>

</html>

Written By: Charles Miller Published in Codeigniter


Search

Publish your passions on srcraftblog.com

Latest Post

☛ Who can be called a true monk ?

☛ God arranges everything

☛ Faith in god

☛ What is a Rotary Encoder? How does it work?

☛ Things to Know About PLC and SCADA

☛ According to Ramayana, why do women wear jewelry?

☛ After registering an FIR, can I not apply for a government job

☛ Daughter: A angel of his father

☛ 'Gurukul' literally means 'family of Guru' or 'clan of Guru'

☛ When does mother's honor get less


We are accepting well-written informative Guest Posts on srcraftblog.com

Innovation & Technology

Artificial Intelligent blogs
Cryptocurrency blogs
Digital India blogs
Data science blogs
Neuroscience blogs
Programming blogs

Physical science

Physics blogs
Chemistry blogs
Earth science blogs
Geology blogs
Oceanography blogs
Meteorology blogs

Industry

Business blogs
Economy blogs
Freelancing blogs
Leadership blogs
Productivity blogs
Work blogs

Society

Basic income blogs
Education blogs
Environment blogs
Media blogs
Philosophy blogs
Women blogs
About us |  Write for us |  Terms and conditions |  Contact us

© 2021 SRCRAFT INIDA