A PHP Error was encountered
Severity: Notice
Message: Undefined variable: id
Filename: models/singlequery_model.php
Line Number: 4
A Database Error Occurred
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
SELECT * FROM patient WHERE id =
文件名:C:\ xampp \ htdocs \ login \ system \ database \ DB_driver.php
行号:330
这是查询单个结果的正确方法吗?
<?php
class Singlequery_model extends CI_Model{
function get_query(){
$query = $this->db->query("SELECT * FROM patient WHERE id = $id");
if($query->num_rows() > 0 ){
foreach ($query->result() as $row){
$data[] = $row;
}
return $data;
}
}
}
以下是我的控制器
<?php
class Site extends CI_Controller{
function __construct(){
parent::__construct();
$this->is_logged_in();
$this->load->model('site_model');
}
function delete(){
$this->site_model->delete_row();
redirect('site/members_area');
}
function view(){
$this->load->model('singlequery_model');
$data['records'] = $this->singlequery_model->get_query();
$this->load->view('patient_update', $data);
}
}
答案 0 :(得分:2)
$query = $this->db->query("SELECT * FROM patient WHERE id = $id");
$id
未在您的课程中定义
为此,请务必使用$id
调用该函数:
$data['records'] = $this->singlequery_model->get_query($id);
我无法知道$id
来自哪里,所以你可以自己管理它。