onclick使用codeigniter从dB显示图像

时间:2018-09-05 08:44:19

标签: php codeigniter

我希望在使用onclick按钮(传递变量)时显示数据库中的图像。

 <a class="btn btn-sm btn-primary" href="<?= 
base_url().'users/viewimage'.$record->userId; 
?>" title="Login history"><i class="fa fa- 
 history"></i></a> | 

控制器

function viewimage(){
    $data = array();

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

    $data['uploaded_images'] = $this->upload_images->get_images();


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

模型

function get_images(){
    $this->db->from('uploaded_images');
    $this->db->order_by('date_uploaded', 'asc');
    $query = $this->db->get();

    return $query->result();        

}

我如何获得它?请提出建议

1 个答案:

答案 0 :(得分:0)

您的视图中的更新

<a class="btn btn-sm btn-primary" href="<?= 
base_url().'users/viewimage/'.$record->userId; 
?>" title="Login history"><i class="fa fa- 
 history"></i></a> | 

在控制器中

function viewimage($userId){
    $data = array();
    $this->load->model('upload_images');
    $data['uploaded_images'] = $this->upload_images->get_images($userId);
    $this->load->view('home', $data);
}

在模型中

function get_images($userId){
    $this->db->from('uploaded_images');
    $this->db->where("userId = $userId");
    $this->db->order_by('date_uploaded', 'asc');
    $query = $this->db->get();
    return $query->result();        
}