I want to count and display a database field.
Database: nbkg
Table: chamados
Model:
chamados_model.php
<?php
class dashboard_model extends CI_Model{
public function lista($chamados)
{
$query = $this->db->query('SELECT * FROM chamados');
echo $query->num_rows();
}
}
Controller:
Dashboard.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Dashboard extends CI_Controller {
public function index() {
$this->load->view('dashboard.php');
$this->load->model("dashboard_model");
$this->load->database();
$this->load->helper('url');
}
}
View:
dashboard.php
<?php echo $query ?>
Error: can not find variable Query
:
A PHP Error was encountered > Severity: Notice > Message: Undefined variable: query > Filename: views / dashboard.php
Line Number: 1
Backtrace:
File: /Applications/MAMP/htdocs/nbkg/application/views/dashboard.php Line: 1 Function: _error_handler
File: /Applications/MAMP/htdocs/nbkg/application/controllers/Dashboard.php Line: 8 Function: view
File: /Applications/MAMP/htdocs/nbkg/index.php Line: 315 Function: require_once