TAGS :Viewed: 13 - Published at: a few seconds ago

[ I get a blank page when I run this PHP/CakePHP code ]

I get a blank page when I run this code I think its something to do with where I close brackets:

<?php 

while($fabid==$fabric_ids[$cnt]['FabricOrdering']['fabric_id'] && $fabcolorid==$fabric_ids[$cnt]['FabricOrdering']['fabric_colour_id'] ){ 



?>


     <?php
                    $i = 0;

                       foreach ($orderEntry as $orderEntry1) {
                            $style = "";

                    if($$orderEntry1['FabricOrdering']['order_entry_headers_id'] && $orderEntry1['FabricOrdering']['finalized_state'] == OrderFinalized::FINALIZED_STATE_APPROVED){
                                $style = "background-color:#f2c7ef";

                            } else {
                                $style = "background-color:red";

                            }
                            ?>

                           <tr  id="<?php echo $new_row['FabricOrdering']['sbos_id'].'-'.$count.'-'.$order_seq.'_'.$fabcolorid;?>"style=" <?php echo $style;  ?>">
<?php }}?>

How to run foreach loop inside a while loop?

Answer 1


First in your code while loop with condition

while($fabid==$fabric_ids[$cnt]['FabricOrdering']['fabric_id'] && $fabcolorid==$fabric_ids[$cnt]['FabricOrdering']['fabric_colour_id'] ){ 

This condition always return true, so it might be go for infinite loop. Put some increment variable to false this condition.

Increment variable like $cnt.

if($$orderEntry1['FabricOrdering']['order_entry_headers_id']

Here $$ .

->set Dedug to 2 to check errors.

Answer 2


The problem should be the $$ sign in your if condition. This would result in an runtime error, because you first use an array as an var name and then accessing the array, which isn't an array.

Just remove one $ sign and it should work

Answer 3


You've got trapped in an infinite loop.

In your where clause you're using this condition.

$fabid==$fabric_ids[$cnt]['FabricOrdering']['fabric_id'] && $fabcolorid==$fabric_ids[$cnt]['FabricOrdering']['fabric_colour_id'].

But nowhere inside the loop you're updating any of the variable. Gothrough your business logic and update the loop.