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 基于RTKLIB框架写的精密单点定位-AR
  • ¥15 PFENet的预训练权重
  • ¥15 程序哪有错误怎么改?
  • ¥15 交换机和交换机之间的链路带宽以及主机带宽的理解
  • ¥15 ai创想家对战模式代码
  • ¥15 集合A由3个2行4列二维数组构成,从集合A中任意取一个二维数组元素、如果该二维数组元素的对应列位置的上、下两数都是奇数,而且仅有2个列是奇数/奇数,则该数组有意义,并放入集合B中打印输出。
  • ¥15 电信IPV6 无法外网访问吗
  • ¥15 有偿求效果比较好的遥感影像匹配的c++代码
  • ¥15 博主,你好,我下载了你的智能网联汽车辅助驾驶安全信息检测系统,现在不会运行,可以教我吗,
  • ¥15 怎么在excle输入下列公式