我已将图像上传到数据库。现在我想在另一个页面显示。但我不知道该怎么做。我已经在互联网上找到了我在网站上找到的视图图像的代码。但它不起作用任何人都可以帮助我。
我的观点
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">
Plan
</h1>
<ol class="breadcrumb">
<li>
<i class="fa fa-dashboard"></i> <a href="index.html">Home</a>
</li>
<li class="active">
<i class="fa fa-file"></i> Floor Plan
</li>
</ol>
</div>
</div>
<!-- /.row -->
<body>
<div id="response"></div>
<div class="well">
<div class="container">
<div class="row">
<table>
<tr>
<td><strong> Title</strong></td>
<td><strong> Client </strong></td>
<td><strong> Draw By</strong></td>
<td><strong> Floor Plan</strong></td>
</tr>
<?php foreach($post as $post){?>
<tr>
<!-- <td><?php //echo $post->id;?></td>-->
<td><?php echo $post->id ; echo ' ';?></td>
<!-- <td><?php echo $post->title ; echo ' ';?></td>
<td><?php echo $post->firstname ; echo ' ';?><?php echo $post->lastname ; echo ' '?></td>
<td><?php echo $post->first_name ; echo ' ';?><?php echo $post->last_name ; echo ' '?></td>-->
<td><?php echo $post->image ; echo ' '?></td>
</tr>
do {
echo "<img src='path/to/image.php?id=".$row['id']."' />";
} while($row = mysql_fetch_assoc(res));
<?php }
?>
</table>
</div>
</div>
</div>
</body>
</html>
控制器
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Floor_plan extends CI_Controller{
public function __construct() {
parent::__construct();
$this->load->database(); // load database
$this->load->model('floor_model');
}
public function index(){
$data['post'] = $this->floor_model->get_plan(); // calling Post model method getPosts()
$this->load->view('user_include/header');
$this->load->view('plan/floor',$data);
}
}
?>
模型
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?>
<?php
class Floor_model extends CI_Model {
function get_plan(){
$this->db->select("floor_plan.id,floor_plan.image");
$this->db->from('floor_plan');
$query = $this->db->get();
return $query->result();
}
}
?>
答案 0 :(得分:1)
请在图像源中提供完整路径,如 -
<?
答案 1 :(得分:0)
<?php echo "<img src='" . base_url().$post->image."' width=150px; height=100px;>";?></td>
此代码工作正常