2016-05-23 24 views
0

我正在嘗試使用codeigniter顯示數據庫中的圖像。當用戶搜索位置時,信息將顯示出來,包括圖像。但我無法展示圖像。我在應用程序外部將文件保存在文件中。這是我的代碼。如何從數據庫codeigniter中顯示圖像

//view.php

<style> 
#searchbutton{ 
position: absolute; 
left:300px; 
top:30px; 
    } 
fieldset { 
background-color:#EFEAEA; 
margin: 0px 0px 10px 0px; 
padding: 20px; 
border-radius: 1px; 
width:900px; 
margin-left:220px; 
margin-top:-10px; 
} 
#user{ 
font-style:italic; 
font-size: 12px; 
text-align:right; 
} 
#titlereview { 
font-style: italic; 
font-size:20px; 
} 
#review { 
font-size:16px; 
} 
</style> 

<?=form_open_multipart('viewreview/view');?> 
<?php $search = array('name'=>'search',);?> 
<div id = "searchbutton"> 
<?=form_input($search);?><input type=submit value="Search" /></p> 
</div> 
<?=form_close();?> 

<div class = "tablestyle"> 
<fieldset> 
<?php foreach ($query as $row): ?> 
<div id = "user"> 
User: <?php echo $row->name; ?><br> 
Visited time: <?php echo $row->visitedtime; ?><br> 
</div> 
<div id = "titlereview">"<?php echo $row->titlereview; ?>"<br></div> 
<div id = "review"><?php echo $row->yourreview; ?><br></div> 
<div id = "image"><?php echo '<img src="data:image/jpeg, $row[images]"/>' ?<br><hr><br></div> 

<?php endforeach; ?> 
</fieldset> 
</div> 

//控制器

<?php 

class viewreview extends CI_Controller { 

public function view($page = 'viewreview') //writereview page folder name 
{ 
    $this->load->model('viewreview_model'); 
    $data['query'] = $this->viewreview_model->get_data(); 
    $this->load->vars($data); 

    if (! file_exists('application/views/viewreview/'.$page.'.php')) //link 
    { 
     // Whoops, we don't have a page for that! 
     show_404(); 
    } 

    $data['title'] = 'View Review'; 
    //$data['title'] = ucfirst($page); // Capitalize the first letter 
    $this->load->helper('html'); 
    $this->load->helper('url'); 
    $this->load->helper('form'); 
    $this->load->view('templates/header', $data); 
    $this->load->view('viewreview/'.$page, $data); 
    $this->load->view('templates/footer', $data); 
} 
} 
?> 

//模型

<?php 
class viewreview_model extends CI_Model { 

public function __construct() 
{ 
    $this->load->database(); 
} 
public function get_data() 
{ 
    $match = $this->input->post('search'); 
    $this->db->like('sitename',$match); 
    $this->db->or_like('titlereview',$match); 
    $this->db->or_like('yourreview',$match); 
    $this->db->or_like('suggestion',$match); 

    $query = $this->db->get('review');  //pass data to query 
    return $query->result(); 
} 

} 
?> 
+0

<?php echo'

回答

0

默認代碼點火器將在STD-的形式返回數據目的。你需要使用 - >(箭頭)訪問它。

例如JD在評論

<?php echo '<img src="data:image/jpeg,'.$row->images.'" />' ?> 

回覆或者你需要的功能傳遞參數「陣」在你的模型

使用這個模型中:return $query->result('array');回報(陣列)

實例:return $query->result();回報(Std-Object)