簡體   English   中英

使用codeigniter從數據庫中顯示圖像及其附帶信息

[英]Displaying images and their accompanying information from a database with codeigniter

好的,我將圖像上傳到服務器上的文件夾,然后嘗試用他們的信息重新顯示它們。

這是我用來提取信息的模型中的函數:

    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;

}

控制器實現如下功能:

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);
}

視圖中存在問題。 我希望每種圖像都以這種格式顯示其信息:

<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>

我試過很多不同的方法來做例如嵌套的foreach語句,但我似乎無法做到正確。 任何幫助,將不勝感激。

謝謝

你可以這樣做:

<?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; ?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM