sunshine
sunshine

Reputation: 381

checking previous row value and display the next row accordingly

How to check, if in the previous row exit_status is completed, and ,depending on that, whether it is completed or pending display the update update button, or else hide it in CodeIgniter. I cannot think of a logic to implement this , and here is my view code:

<?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 }

And if the previous row exit_status is completed only then open up the update button else hide it. something like.. if($row['sequence']-1) == 'completed' {display the button else hide} . Attached view image

enter image description here

Upvotes: 4

Views: 670

Answers (1)

Atural
Atural

Reputation: 5439

if i understand you correctly - you want access to the previous "Row" value within the foreach

in order to do that you can try something like this

i assumed that your keys are numeric and are starting with 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
        }


    }
}

A better solution would be to implement an ArrayIterator http://php.net/manual/de/class.arrayiterator.php

Upvotes: 1

Related Questions