2016-05-12 2 views
0

Я хочу, чтобы показать конкретное изображение, когда значение строки возвращается из БДпоказать изображение со значением строки, используя, если заявление в CodeIgniter

Например: Когда значение возвращается как 1 я хочу показать fire

Но я знаю только код PHP в CodeIgniter я получаю сообщение об ошибке 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

Почему бы вам не попробовать, чтобы добавить изображения в окне просмотра,

В контроллере

$list = $this->person->get_datatables_vandaag(); 
$this->load->view('your-view.php',$list); 

ваш-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> 
Смежные вопросы