dongzi5673 2014-11-28 08:46
浏览 37
已采纳

在codeigniter中查看传递数组不起作用

So my problem is that the values from this specific id won't print. I really don't know what's the problem since there is no error. please help guys. Still a newbie at using this framework. thanks!

controller:

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

  $this->load->view('teacher/teacher', $data);
 } 

model:

class Model_teacher extends CI_Model {

    public function scoreboard($id) {

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

        }
} 

view:

 <?php
    foreach ($result as $a) {
            echo $a['login_id'];
            echo $a['lname'];
            echo $a['mname'];
            echo $a['fname'];
        }

 ?>
  • 写回答

1条回答 默认 最新

  • duangan6731 2014-11-28 09:00
    关注

    Alternative to Ghost's answer:

    To keep you model the same you would just need to change your view file from:

    foreach ($result as $a) {
            echo $a['login_id'];
            echo $a['lname'];
            echo $a['mname'];
            echo $a['fname'];
        }
    

    To:

    foreach ($result as $a) {
            echo $a->login_id;
            echo $a->lname;
            echo $a->mname;
            echo $a->fname;
        }
    

    This is because result() with the DB driver returns an array of Objects where as result_array() returns an array of arrays.

    Hope this helps!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示