douaonong7807 2014-11-28 06:36
浏览 46
已采纳

codeigniter中的模型将无法识别ID号

So here is the error:

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: idnum

Filename: models/model_teacher.php

Line Number: 8

this is my controller:

 public function teacher(){

   $this->load->model('model_teacher');

   $data['result'] = $this->model_teacher->scoreboard();
   $this->load->view('teacher/teacher', $data);
  }

and my model:

 class Model_teacher extends CI_Model {

    public function scoreboard() {

        $this->db->where('login_id', $this->input->post('idnum'));
        $query = $this->db->query("SELECT * FROM teacher WHERE login_id = '".$idnum."'");
        return $query->result();

        }
} 

and the view:

<?php
  foreach ($result as $row) {
            echo $row->login_id."<br>";
            echo $row->lname."<br>";
        }
?>

and don't know what is wrong with this code. please bear with me, i'm still a newbie at using codeigniter. thanks guys.

  • 写回答

3条回答 默认 最新

  • dougongnan2167 2014-11-28 06:43
    关注

    you can't get directly in model you have to first get in controller Controller

       public function teacher(){
    $id  = $this->input->post('idnum');
    
       $this->load->model('model_teacher');
    
       $data['result'] = $this->model_teacher->scoreboard($id);
       $this->load->view('teacher/teacher', $data);
      }
    

    Model`

    public function scoreboard($idnum) {
    
        $query = $this->db->query("SELECT * FROM teacher WHERE login_id = '".$idnum."'");
        return $query->result();
    
        }`
    

    This is the code you can use

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数