我正在尝试使用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 :(得分:0)
默认情况下,Code-igniter将以std-object的形式返回数据。您需要使用 - &gt;访问它(箭头)。
e.g。 jd回复评论
<?php echo '<img src="data:image/jpeg,'.$row->images.'" />' ?>
或者您需要在模型中的函数中传递参数'array'
在你的模型中使用它:return $query->result('array');
return(Array)
实例:return $query->result();
返回(标准对象)