doukeng1922 2017-01-28 14:22
浏览 59
已采纳

使用codeigniter不显示数据库中的值

I'm new using codeigniter. I'm trying to display items from my database, but I don't know why it doesn't work. Could you help me, please?

My Controller

function Usuario extends CI_Controller{
    function construct(){
        parent::__construct();
        $this->load->model('usuario_m');
    }
    public function modificar_usuario(){
        $id_usuario = 1;
        $this->load->model('usuario_m');
        $data['resultado'] = $this->usuario_m->ver_datos_usuario($id_usuario);
        $this->load->view('paginas/modificar_usuario',$data);

    }

This is my Model:

public function ver_datos_usuario($id_usuario)
{

    $this->db->select('nombre','apellido','nro_ci', 'direccion','email','telefono','password');
    $this->db->where('id_usuario', $id_usuario);
    $this->db->from('usuarios');
    $query = $this->db->get();
    return $resultado = $query->result();

}

And this is my view: (Edited)

<!DOCTYPE>
<head>
<html>
<body>
<?php 
foreach ($data as $d){?>
    <label>Nombre: </label>
    <input type="text" value="<?php echo $d->nombre;?>" />
<?php } ?> 
</body>
</html>

What I'm doing wrong?

  • 写回答

3条回答 默认 最新

  • dtfpznrbn503027700 2017-01-28 14:30
    关注

    Change this

    foreach ($data as $d){?>
    

    as following

    foreach($resultado as $d){?>
    

    because you are sending resultado to view in $data array so now $resultado can be access as returned result from model

    One more suggestion

    Instead return result like return $resultado = $query->result(); use this return $query->result();

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

报告相同问题?

悬赏问题

  • ¥15 请问以下文字内容及对应编码是用了什么加密算法或压缩算法呢?
  • ¥50 关于#html5#的问题:H5页面用户手机返回的时候跳转到指定页面例如(语言-javascript)
  • ¥15 无法使用此凭据登录,因为你的域不可用,如何解决?(标签-Windows)
  • ¥15 yolov9的训练时间
  • ¥15 二叉树遍历没有报错但无法正常运行
  • ¥15 在linux系统下vscode运行robocup3d上场球员报错
  • ¥15 Python语言实验
  • ¥15 SAP HANA SQL 增加合计行
  • ¥20 用C#语言解决一个英文打字练习器,有偿
  • ¥15 srs-sip外部服务 webrtc支持H265格式