这是我的模特外观
public function fetchimage(){
$this->db->select('u_id,file_name');
$this->db->from('image');
if($this->session->userdata('id')){
$this->db->where('u_id',$this->session->userdata('id'));
$query = $this->db->get();
$query->result_array();
$result = $query->row_array();
echo '<pre>';
print_r($query);
die();
}
return !empty($result)?$result:false;
}
这是我的视图
<?php
$this->load->model('user');
$data['uploadData'][] = $this->user->fetchimage();
?>
<div class="row">
<ul class="gallery">
<?php if($data['uploadData']){ foreach($data['uploadData'] as $data['uploadData']){
?>
<li class="item">
<img src="<?php echo base_url('/assets/uploads/files/'.$data['uploadData']['file_name']); ?>" >
</li>
<?php } }else{ ?>
<p>Image(s) not found.....</p>
<?php } ?>
</ul>
</div><br>
图像无法全部打印。它仅打印一张图像。当我采取foreach循环。 在Model i中,打印查询,即打印所有图像,但在视图中不打印图像。
答案 0 :(得分:0)
尝试一下
row_array()
将为您提供具有数组格式数组的单行,而result_array()
将为您提供具有数组格式数组的多行。
public function fetchimage(){
$this->db->select('u_id,file_name');
$this->db->from('image');
if($this->session->userdata('id')){
$this->db->where('u_id',$this->session->userdata('id'));
$query = $this->db->get();
$result = $query->result_array();
echo '<pre>';print_r($query);die();
}
return !empty($result)?$result:false;
}
查看:
<?php
$this->load->model('user');
$data['uploadData'] = $this->user->fetchimage();
?>
<div class="row">
<ul <?php if ($data['uploadData']) {
foreach ($data['uploadData'] as $rowData) { ?>
<li class="item">
<img src="<?php echo base_url('/assets/uploads/files/' .$rowData['file_name']); ?>" >
</li>
<?php } } else { ?>
<p>Image(s) not found.....</p>
<?php } ?>
</ul>
</div>
<br>