行数组中的数据表if语句

时间:2017-07-30 14:48:58

标签: codeigniter if-statement datatable

所以我在codeigniter中使用了一个数据表来显示我现在查询的所有row []数组我的问题是,如何在一个行[]数组中放置一个条件语句我已经尝试了所有可能的方法适合但错误会说我无法在行[]中定义if语句这里是我的代码:

foreach ($list as $foo_app) {
       $ApplicationNo++;
       $row = array();

       $row[] = $foo_app->ApplicationNo;
       $row[] = $foo_app->UserId;
       $row[] = $foo_app->FirstName.''.$foo_app->LastName;
       $row[] = $foo_app->PlateNo;
       $row[] = $foo_app->DateApplied;
       $row[] = if (.$foo_app->Status_Application. === "In-Active") {
        <b class="w3-padding w3-gray w3-hover-white w3-round-xxlarge">
        }
        elseif (.$foo_app->Status_Application. === "Accepted") {
        <b class="w3-padding w3-green w3-hover-white w3-round-xxlarge">
       }
       elseif (.$foo_app->Status_Application. === "Denied") {
        <b class="w3-padding w3-red w3-hover-white w3-round-xxlarge">
       };
       $row[] = '<div style="text-align: center;">&#8369;'.$foo_app->AmountFinanced.'</div>';

2 个答案:

答案 0 :(得分:1)

首先编写if子句,然后将结果添加到row [],如下所示:

$html='';    
if ($foo_app->Status_Application. === "In-Active") {
    $html='<b class="w3-padding w3-gray w3-hover-white w3-round-xxlarge">';
    }
    elseif ($foo_app->Status_Application. === "Accepted") {
    $html='<b class="w3-padding w3-green w3-hover-white w3-round-xxlarge">';
   }
   elseif ($foo_app->Status_Application. === "Denied") {
    $html='<b class="w3-padding w3-red w3-hover-white w3-round-xxlarge">';
};

$row[]=$html;

答案 1 :(得分:1)

比较字符串时,您可以使用字符串函数

$html = "";
if (!strcasecmp($foo_app->Status_Application,"In-Active")) {
    $html='<b class="w3-padding w3-gray w3-hover-white w3-round-xxlarge">';
    }
    elseif (!strcasecmp($foo_app->Status_Application,"Accepted")) {
    $html='<b class="w3-padding w3-green w3-hover-white w3-round-xxlarge">';
   }
   elseif (!strcasecmp($foo_app->Status_Application,"Denied")) {
    $html='<b class="w3-padding w3-red w3-hover-white w3-round-xxlarge">';
};

$行[] = $ HTML;