使用codeigniter中的if语句显示带行值的图像

时间:2016-05-12 07:11:51

标签: codeigniter

我想在从db

返回行值时显示特定图像

例如: 当值返回为1时,我想显示fire

但是我只知道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>

1 个答案:

答案 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>