doumeng4400 2013-07-23 20:16
浏览 27
已采纳

使用codeigniter从数据库中显示图像及其附带信息

Ok so im uploading images to a folder on my server, and then trying to re-display them with their information.

This is the function in my model that i am using to pull the info:

    public function pull_all(){

    $this->db->select('file_name, file_type, full_path, image_type');
    $query = $this->db->get('img');
    $dbInfo = $query->result_array();
    return $dbInfo;

}

The controller implements the function like so:

function show_all(){

    $this->load->model('image_work');
    $data = array('dbInfo' => $this->image_work->pull_all());

    $data['title'] = "Uploads";
    $this->load->view('templates/header', $data);
    $this->load->view('show_all',$data);
    $this->load->view('templates/footer', $data);
}

The problem iv been having is in the view. I want each image to be shown with its info in this format:

<ul class="thumbnails">
<li class="span3">
    <div class="thumbnail">
        <img src="$location_stored_in_database"/>
        <h3>$image_name</h3>
        <p>$image_type</p>
        <p>$image_size</p>
        <p>$image_dimensions</p>
    </div>
</li>

Iv tried many different ways to do it for example nested foreach statements, but I just cant seem to get it right. Any help would be appreciated.

thanks

  • 写回答

1条回答 默认 最新

  • duanbeng8872 2013-07-23 20:24
    关注

    You can do like this:

    <?php foreach($dbInfo as $image): ?>
    <ul class="thumbnails">
    <li class="span3">
        <div class="thumbnail">
            <img src="<?php echo $image['full_path']; ?>"/>
            <h3><?php echo $image['image_name']; ?></h3>
            <p><?php echo $image['image_type']; ?></p>
            <p><?php echo $image['image_size']; ?></p>
            <p><?php echo $image['image_dimensions']; ?></p>
        </div>
    </li>
    <?php endforeach; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵