【发布时间】:2019-01-16 05:12:17
【问题描述】:
我尝试了不同的方法,但到目前为止没有。这里有类似的主题,但它们似乎并没有解决我的特殊情况。我想显示来自“images”表的单个用户个人资料图像,其中包含指向“users”表的外键链接。我有一个可行的方案,但它使用“foreach”语句显示多个图像。图像也保存在根目录的本地“上传”文件夹中。以下是适用于视图中多个图像的代码:
<?php foreach($images_model as $images):?>
<img src="<?php echo base_url()."uploads/".$images->fileName;?>" alt="" class="img-thumbnail">
其中“fileName”是“images”表中的列。 images_model 看起来像这样:
function get_images(){
$this->db->from('images');
$this->db->order_by('date_uploaded', 'asc');
$query = $this->db->get();
return $query->result();
}
来自控制器的图片上传部分如下:
if($this->upload->do_upload()) {
$file_data = $this->upload->data();
$data['user_id'] = $this->session->userdata('user_id');
$data['fileName'] = $file_data['file_name'];
$data['filePath'] = $file_data['full_path'];
$data['fileType'] = $file_data['file_type'];
$data['fileSize'] = $file_data['file_size'];
$data['date_uploaded'] = date('Y/m/d H:i:s');
}
Here is the necessary portion of the ‘images’ table:
是否有一种轻松的方式来显示“images”表中的单个图像,该方法会考虑到“images”表中的外键活动“user_id”?换句话说,将用户想要的图像显示为个人资料。
感谢您的帮助。感谢任何和所有输入。
【问题讨论】:
-
在您的模型函数中,您从表中获取所有记录,因此显示了多个图像。您希望显示单个用户图像吗?
标签: codeigniter foreign-keys image-uploading user-profile