我想在从db
返回行值时显示特定图像但是我只知道codeigniter中的php代码我得到错误tn7
控制器:
public function ajax_list()
{
$list = $this->person->get_datatables_vandaag();
$data = array();
$no = $_POST['start'];
foreach ($list as $person) {
$no++;
$row = array();
$current = $row[] = $person->doel;
if($current=='3') {echo 'image' ;}
elseif($current=='4') {echo 'image' ;}
elseif($current=='2') {echo 'image' ;}
elseif($current=='1') {echo 'image' ;}
$row[] = $person->firm;
$row[] = $person->name;
$row[] = $person->phone;
}
视图:
<table id="table" class="table table-striped table-bordered table-responsive" cellspacing="0" width="100%">
<thead>
<tr>
<th></th>
<th style="width:100px;">Firm</th>
<th style="width:100px;">Name</th>
<th style="width:75px;">number</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
答案 0 :(得分:0)
为什么不尝试在视图中添加图片,
在控制器中
$list = $this->person->get_datatables_vandaag();
$this->load->view('your-view.php',$list);
your-view.php文件
<table id="table" class="table table-striped table-bordered table-responsive" cellspacing="0" width="100%">
<thead>
<tr>
<th></th>
<th style="width:100px;">Firm</th>
<th style="width:100px;">Name</th>
<th style="width:75px;">number</th>
</tr>
</thead>
<tbody>
<?php
foreach ($list as $key => $person) {
echo '<tr>';
echo '<td>';
if($key=='3')
{echo 'image' ;}
elseif($key=='4') {echo 'image' ;}
elseif($key=='2') {echo 'image' ;}
elseif($key=='1') {echo 'image' ;}
echo '</td>';
echo '<td>'.$person->firm.'</td>';
echo '<td>'.$person->name.'</td>';
echo '<td>'.$person->number.'</td>';
echo '</tr>';
}
</tbody>
</table>