检查前一行值并相应地显示下一行

checking previous row value and display the next row accordingly

如何检查,如果在上一行 exit_status 中完成,并且取决于它是完成还是等待显示更新更新按钮,或者将其隐藏在 CodeIgniter 中。我想不出实现这个的逻辑,这是我的视图代码:

<?php } else if($USER->permissions[0] == 'all' && $row['responsibility'] == $USER->email && $row['completion_status'] == 'Pending'&& $row['sequence']-1 == 'completed') { ?>

<td style="width:10%">
  <input type="hidden" name="grievance_id" value="<?=$row['id']?>">
  <input type="hidden" name="action" value="update">

  <input type="submit" <?=($row[ 'checklist_id']=="Denied" ||$row[ 'checklist_id']=="Approved" )? "disabled='true'": "";?>name="sumit_button" value="Update" class="btn" style="float:left;background:#d8d8d8;color:#000;box-shadow:0px 0px 1x rgba(0,0,0,0.2)!important;"> &nbsp;&nbsp;

</td>
<?php }

如果上一行 exit_status 完成,则只打开更新按钮,否则将其隐藏。像.. if($row['sequence']-1) == 'completed' {display the button else hide} 。附加视图图像

enter image description here

如果我理解正确的话 - 你想要访问 foreach

中的前一个 "Row" 值

为了做到这一点,你可以尝试这样的事情

我假设您的键是数字键并且以 0 开头

if(count($rows) > 0)
{ 
    foreach($rows as $key => $row)
    {
        $prevRow = (isset($rows[($key-1)])) ?   $rows[($key-1)] :   false;

        if($USER->permissions[0] == 'all' && $row['responsibility'] == $USER->email && $row['completion_status'] == 'Pending'&& ($prevRow && $prevRow['sequence'] == 'completed'))
        {

            //your code goes here
        }


    }
}

更好的解决方案是实现 ArrayIterator http://php.net/manual/de/class.arrayiterator.php