1
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: does not find the variable Query
:
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
now giving error An Error Was Encountered Unable to load the requested class: Database
– Davi R Rossini
Retire
$this->load->library('database');
and add'database'
in thearray
of the archiveapplication/config/autoload.php
in the key$autoload['libraries']
.– William Novak
And in the view I call $list. correct?
– Davi R Rossini
No, keep it intact if you followed my example. The variable is called
$query
(see the key toarray
that it turns into variables).– William Novak
Done!! Thank you
– Davi R Rossini