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

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

图片转代码服务由CSDN问答提供 功能建议

好的,我将图像上传到服务器上的文件夹,然后尝试用它们的信息重新显示它们。

这是我模型中用来提取信息的函数:

  public function pull_all(){
 \  n $ this-&gt; db-&gt; select('file_name,file_type,full_path,image_type'); 
 $ query = $ this-&gt; db-&gt; get('img'); 
 $ dbInfo = $  query-&gt; result_array(); 
返回$ dbInfo; 
 
} 
   
 
 

控制器实现如下函数: <前> function show_all(){ $ this-&gt; load-&gt; model('image_work'); $ data = array('dbInfo'=&gt; $ this-&gt ; image_work-&gt; pull_all()); $ data ['title'] =“上传”; $ this-&gt; load-&gt; view('templates / header',$ data); \ n $ this-&gt; load-&gt; view('show_all',$ data); $ this-&gt; load-&gt; view('templates / footer',$ data); }

iv中存在的问题出现在视图中。 我希望每个图像都以这种格式显示其信息:

 &lt; ul class =“thumbnails”&gt; 
&lt; li class =“span3”&gt; \  n&lt; div class =“thumbnail”&gt; 
&lt; img src =“$ location_stored_in_database”/&gt; 
&lt; h3&gt; $ image_name&lt; / h3&gt; 
&lt; p&gt; $ image_type&lt; / p&gt; \  n&lt; p&gt; $ image_size&lt; / p&gt; 
&lt; p&gt; $ image_dimensions&lt; / p&gt; 
&lt; / div&gt; 
&lt; / li&gt; 
   
 
  

Iv尝试了很多不同的方法来做例如嵌套的foreach语句,但我似乎无法将其弄好。 任何帮助将不胜感激。

谢谢

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题