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条)

报告相同问题?

悬赏问题

  • ¥33 集成BiLSTM模型和GCN模型时,前模型的输出不匹配后模型的输入
  • ¥15 关于液体厚度提取,和铺展轨迹数据化处理
  • ¥20 对方微信是wxid如何添加成好友?或者转换成微信号?
  • ¥15 yolov5实验数据好,但是自己拍摄的照片检测结果差
  • ¥15 做过dali2.0认证的技术,
  • ¥15 一道python难题
  • ¥15 matlab 免疫算法
  • ¥50 可视化界面构建,实现信息模块功能
  • ¥15 基于bert-base-chinese的中文文本处理
  • ¥15 高价求抖音抓包技术,抖音抓包无网络问题