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 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?