我一直在查看codeigniters网站的活动记录指南,我试图在模型或控制器中找出where子句的位置?我认为它属于模型,但不确定如何实现它。 $ where =" EmpName =' Donny&#34 ;; $这 - > DB-化合物其中($其中);
控制器名为Home.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller
{
public function index()
{
$this->load->model('HomeModel');
$data['records'] = $this->HomeModel->getData();
$this->load->view('HomeView',$data);
}
}
HomeModel.php
<?php
class HomeModel extends CI_Model{
public function getData(){
$query = $this->db->get('requests');
return $query->result();
}
}
HomeView.php
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Home View</title>
</head>
<body>
<h1>Our DB Results:</h1>
<?php
foreach($records as $r){
echo $r->EmpName." ".$r->Department."<br>";
};?>
</body>
</html>
答案 0 :(得分:1)
试试这个
$query = $this->db->get_where('requests', array('id' => $id));
你可以使用
$this->db->where('empname', 'Donny');
答案 1 :(得分:0)
试试这个
$query = $this->db->get_where('requests', array( 'EmpName' => 'Donny' ));
return $query->result();