General |  Social Media |  Miscellaneous
srcraft blog logo
  • Business
  • News
  • Shopping
  • Travel
  • Disease
  • Pets
  • Life
  • Health
  • Technology
  • Category
  • Contact Us
Latest Blog : 
☛ Top 3 Statistics Assignment Help Services in Australia ☛ Personalized Fabrication Options for Your Business Requirements ☛ Driving India's Economic Growth: The Role of Strategic Government Policies ☛ Affordability in Travel: The Cheapest Modes of Transportation in India ☛ Analyzing Social Media Strategies and Online Marketing Trends ☛ Understanding Leadership: Definition and Strategic Insights ☛ Freelance Jobs: An Overview ☛ Understanding Meteorology: The Science of Weather and Climate ☛ Diving into Oceanology: Careers in Marine Science ☛ Exploring Oceanography: The Science of the Seas 
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

☛ Personalized Fabrication Options for Your Business Requirements

☛ Driving India's Economic Growth: The Role of Strategic Government Policies

☛ Affordability in Travel: The Cheapest Modes of Transportation in India

☛ Analyzing Social Media Strategies and Online Marketing Trends

☛ Understanding Leadership: Definition and Strategic Insights

☛ Freelance Jobs: An Overview

☛ Understanding Meteorology: The Science of Weather and Climate

☛ Diving into Oceanology: Careers in Marine Science

☛ Exploring Oceanography: The Science of the Seas

☛ The Intersection of Geology and Geography: An In-Depth Exploration


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 |  Privacy Policy |  Our Services |  Contact us

© 2025 SRCRAFT INIDA