General |  Social Media |  Miscellaneous
Login
srcraft blog logo
  • Business
  • News
  • Shopping
  • Travel
  • Disease
  • Pets
  • Life
  • Health
  • Technology
  • Category
  • Contact Us
Latest Blog : 
☛ Save Trees to Save Your Children Life ☛ Importance of practice: A story of Gurukul ☛ Cowards never remember a favor and the brave never forget a favor ☛ The true story: One and Half Ticket ☛ ghhjhjh ☛ Don't mess with health, let's know some important things related to health ☛ How was Shani Dev born and how was his vision crooked? ☛ Story of creation of man, hunger and thirst? ☛ Why is it advised to eat garlic on an empty stomach? ☛ Indian Culture: Wisdom of sages 
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

☛ Save Trees to Save Your Children Life

☛ Importance of practice: A story of Gurukul

☛ Cowards never remember a favor and the brave never forget a favor

☛ The true story: One and Half Ticket

☛ Don't mess with health, let's know some important things related to health

☛ How was Shani Dev born and how was his vision crooked?

☛ Story of creation of man, hunger and thirst?

☛ Why is it advised to eat garlic on an empty stomach?

☛ Indian Culture: Wisdom of sages

☛ Untold Story: Last debt pyre wood


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

© 2023 SRCRAFT INIDA