我想根据条件更改表格的行颜色

时间:2015-10-12 11:49:00

标签: javascript php cakephp

 <tr  id="<?php echo $new_row['Ordering']['sid'].'-'.$count.'-'.$order_seq.'_'.$colorid;?>"
      <?php  if ($orderEntry['Order']['state'] == Order::FINALIZED_STATE_APPROVED)
             echo ' Approved"';
       else 
             echo 'Not Approved';?>"                                    
  ?>  >

我是cakephp和php的新手,目前我只获得第一行的状态。我想将这个条件应用于整个表。请告诉我。

这是我的表格:

       <div class="accBox">

                        <p class="accordianHead"><?php echo $fabric_ids[$cnt]['FabricRange']['name'];?> - <?php echo $fabric_ids[$cnt]['FabricRangeColour']['name'];?> - <?php echo $itemCount;?> Items<span class="floatRight"><?php /*?>56<?php */?></span></p>

                        <div class="accordianBody">

            <?php echo($form->create('FabricOrdering', array('action' => 'pur_wizard', "id" => "form_".$key))); ?>  

                            <table class="accTable" width="100%" border="0" cellspacing="0" cellpadding="0" id="item_tbl_<?php echo $key;?>">
                              <thead class="greyBg paddingHead"> 
                                    <tr>                
                                        <th width="9%">SBOS ID</th>
                                        <th width="9%">Width</th>
                                        <th width="9%">Drop</th>
                                        <th width="9%">PR</th>
                                        <th width="9%">Cut Direction</th>
                                        <th width="15%">Cut With</th>
                                        <th width="9%">Cut Length</th>
                                        <th width="9%">S.I.W</th>
                                        <th width="9%">Fabric Width</th>
                                        <th width="15%">&nbsp;</th>
                                    </tr> 


                                    <?php
foreach($finalizedOrderEntries as $orderEntry) 
{?>



                 </thead>  
                                <tbody>


                <?php                

                echo $this->Form->hidden('fabric_id',array('value' =>$fabric_ids[$cnt]['FabricOrdering']['fabric_id'], 'id' => 'fabric_id'.$key, 'name' => 'fabric_id'));
                echo $this->Form->hidden('fabric_colour_id',array('value' => $fabric_ids[$cnt]['FabricOrdering']['fabric_colour_id'],'id' => 'fabric_colour_id'.$key)); 


                $m=0;
                $val='';
                $chk_val='';
                $all_ids ='';
                $all_order_entry_item_ids='';
                $counter=1;
                $array_length = $itemCount;                             
                $check_order_entry_item_id = '';

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

                    $new_row = $fabric_ids[$cnt];   

                                  if($check_order_entry_item_id != $new_row['FabricOrdering']['order_entry_item_id']){

                                     $m = 0;
                                     $check_order_entry_item_id = $new_row['FabricOrdering']['order_entry_item_id'];
                                  }

                                  $count = $new_row['FabricOrdering']['fabric_order_sort'];
                                                                  $order_seq = $new_row['FabricOrdering']['fabric_order_seq'];      

                                  // $_o_e_i = $new_row['FabricOrdering']['sbos_id'];
                                  // echo $count;
                                  $id = $new_row['FabricOrdering']['id'];
                                  $order_entry_item_id = $new_row['FabricOrdering']['order_entry_item_id'];
                                  if($counter != $array_length){
                                       $all_ids .= $id.',';
                                       $all_order_entry_item_ids .= $order_entry_item_id.',';
                                  } else {
                                       $all_ids .= $id;
                                       $all_order_entry_item_ids .= $order_entry_item_id;
                                  }
                                  $val = $new_row['FabricOrdering']['sbos_id'];
                                  if($val != $chk_val) {
                                       $chk_val = $val;
                                  }
                                  $m++;



                              $cut_width_id_val = 'form_'.$key.'_cutwidth'.$new_row['FabricOrdering']['sbos_id'].'-'.$count.'-'.$order_seq;

                              $sbos_ids_arr = $complete_sbos_id_arr;

                              $cur_key = $new_row['FabricOrdering']['sbos_id'].'-'.$count.'-'.$order_seq;

                              if(count($sbos_ids_arr) >= 1)
                              unset($sbos_ids_arr[$cur_key]);

                              ?>



                           <tr  id="<?php echo $new_row['FabricOrdering']['sbos_id'].'-'.$count.'-'.$order_seq.'_'.$fabcolorid;?>" class="<?php echo ($orderEntry['OrderFinalized']['finalized_state'] != OrderFinalized::FINALIZED_STATE_APPROVED) ? 'approved' : 'unapproved' ; ?>" >


                                        <td><?php echo $new_row['FabricOrdering']['sbos_id'].' - '.$count.' - '.$order_seq;?>aa</td>
                                        <td><?php echo $new_row['FabricOrdering']['width'];
                                        echo $this->Form->hidden('width', array( 'value' => $new_row['FabricOrdering']['width'], 'label' =>  false, 'id'=>'form_'.$key.'width'.$new_row['FabricOrdering']['sbos_id'].'-'.$count.'-'.$order_seq ,  'name' => 'width'.$key.'[]','div' => false));
                                        echo $this->Form->hidden('fabric_color_id', array( 'value' => $fabcolorid, 'id' => 'tr_fabric_color_id'  ));
                                                                                echo $this->Form->hidden('fabric_front_or_back',array('value' => $fabric_ids[$cnt]['FabricOrdering']['fabric_front_or_back'],'id' => 'fabric_front_or_back'.$id));
                                        echo $this->Form->hidden('qty_id',array('value' =>$order_seq, 'id' => 'qty_id'.$id)); // here $order_seq maps with piq_no on order_item_workflows table. 
                                                                                echo $this->Form->hidden('line_id',array('value' =>$count,  'id' => 'line_id'.$id)); // here $count maps with order_seq on order_item_workflows table. 

                                                                                ?> 

                                                                                </td>
                                        <td><?php echo $new_row['FabricOrdering']['drop'];
                                        echo $this->Form->hidden('drop', array( 'value' => $new_row['FabricOrdering']['drop'], 'label' =>  false,'id'=>'form_'.$key.'drop'.$new_row['FabricOrdering']['sbos_id'].'-'.$count.'-'.$order_seq ,  'name' => 'drop'.$key.'[]','div' => false));
                                        ?></td>
                                        <td><?php echo $new_row['FabricOrdering']['pr'];?></td>
                                        <td>
                                            <label for="textfield"></label>
                                            <?php
                                            echo $this->Html->image('busy.gif', array('alt' => 'Ok','id'=>$id.'cut_directionbusy','style'=>'display:none;'));                                        $values ='';
                                            if($new_row['FabricOrdering']['cut_direction']=='3'){
                                                 $values = array('0'=> ' ','2' => 'Across', '1' => 'Down');
                                                }else{
                                                     $values = array('2' => 'Across', '1' => 'Down');
                                                }

                                            echo $this->Form->input('cut_direction', array('options' => $values, 'label' => '' ,'disabled'=> $new_row['FabricOrdering']['disabled'] ,'id'=>'form_'.$key.'cut_direction'.$new_row['FabricOrdering']['sbos_id'].'-'.$count.'-'.$order_seq , 'selected' => $new_row['FabricOrdering']['cut_direction'], 'onchange' => 'updateField("'.$key.'","'.$id.'", "cut_direction", this.value,null,null),updateCutWith("'.$id.'",this.value,"form_'.$key.'_cutlength'.$new_row['FabricOrdering']['sbos_id'].'-'.$count.'-'.$order_seq.'","'.$new_row['FabricOrdering']['width'].'","'.$new_row['FabricOrdering']['drop'].'");'));
                                            ?>
                                        </td>
                                        <td>
                                            <div class="form-group">
                                            <?php
                                            echo $this->Html->image('busy.gif', array('alt' => 'Ok','id'=>$id.'cut_widthbusy','style'=>'display:none;'));
                                            echo $this->Form->input('cut_width', array('options' => $sbos_ids_arr ,'label' => '','selected' => $new_row['FabricOrdering']['cut_width'], 'multiple'=>'multiple', 'class'=>'form-control, ms' ,'id'=>'form_'.$key.'_cutwidth'.$new_row['FabricOrdering']['sbos_id'].'-'.$count.'-'.$order_seq, 'disabled'=> $new_row['FabricOrdering']['disabled'], 'onchange' => 'updateField(null,"'.$id.'", "cut_width", this.value, null,null)'));
                        ?>        
                                            </div>
                                        </td>
                                        <td>

                                            <?php
                                            echo $this->Html->image('busy.gif', array('alt' => 'Ok','id'=>$id.'cut_lengthbusy','style'=>'display:none;'));
                                            $cut_direction_value='';
                                            if($new_row['FabricOrdering']['cut_direction']==1){
                                                $cut_direction_value =  $new_row['FabricOrdering']['drop']+50;
                                            } else if($new_row['FabricOrdering']['cut_direction']==2){
                                                $cut_direction_value =  $new_row['FabricOrdering']['width']+50;
                                            }
                                            echo $this->Form->input('cut_length', array('value' => ($new_row['FabricOrdering']['cut_length']==0)?$cut_direction_value:$new_row['FabricOrdering']['cut_length'], 'label' => '', 'disabled'=> $new_row['FabricOrdering']['disabled'] , 'onchange' => 'updateField(null,"'.$id.'", "cut_length", this.value, null,null),updateCutDirectionValue("'.$id.'",this.value,"form_'.$key.'cut_direction'.$new_row['FabricOrdering']['sbos_id'].'-'.$count.'-'.$order_seq.'","'.$new_row['FabricOrdering']['width'].'","'.$new_row['FabricOrdering']['drop'].',0");', 'id' => 'form_'.$key.'_cutlength'.$new_row['FabricOrdering']['sbos_id'].'-'.$count.'-'.$order_seq , 'name' => 'cut_length'.$key.'[]'));

             echo $this->Form->hidden('is_cutwith', array( 'value' => ($new_row['FabricOrdering']['cut_width']!="" && $new_row['FabricOrdering']['disabled']!=0 )? $new_row['FabricOrdering']['cut_width']: $new_row['FabricOrdering']['sbos_id'].'-'.$count.'-'.$order_seq , 'label' =>  false,'id'=> 'is_cutwith'.$id ,  'name' => 'is_cutwith'.$key.'[]','div' => false));
             $_hidden_counter_value ='';

                        if($new_row['FabricOrdering']['disabled'] == "0" &&  $new_row['FabricOrdering']['cut_width'] !="0" && $new_row['FabricOrdering']['cut_width'] != NULL && $new_row['FabricOrdering']['cut_width'] != ''){
                            $_hidden_counter_value ='';
                            $_hidden_counter_value ="multicheck";
            }

                        if(($new_row['FabricOrdering']['disabled'] =='0') &&  $new_row['FabricOrdering']['cut_width']=='0' || $new_row['FabricOrdering']['cut_width']==NULL || $new_row['FabricOrdering']['cut_width']==''){
                            $_hidden_counter_value ='';
                            $_hidden_counter_value ="single";
                        }

                        if(($new_row['FabricOrdering']['disabled'] =='1')){
                            $_hidden_counter_value ='';
                            $_hidden_counter_value ="child";
                        }

                        echo $this->Form->hidden('hidden_counter', array( 'value' =>$_hidden_counter_value, 'label' =>  false,'id'=> 'hidden_counter'.$id ,  'name' => 'hidden_counter'.$key.'[]','div' => false));
                        ?>
                                        </td>
                                        <td>
                                            <?php 
                                            echo $this->Html->image('busy.gif', array('alt' => 'Ok','id'=>$id.'s_i_widthbusy','style'=>'display:none;'));
                                            echo $this->Form->input('s_i_width', array('class' => 'className', 'name'=> 's_i_width[]','type'=>'checkbox', 'value' => $id, 'label' => '','id'=>'form_'.$key.'s_i_width'.$new_row['FabricOrdering']['sbos_id'].'-'.$count.'-'.$order_seq));
                                            ?>
                                        </td>
                                        <td>
                                            <?php
                                            echo $this->Form->hidden('fabric_name',array('value' => $new_row['FabricRange']['name'],'id' => 'fabric_name'.$key));
                                            echo $this->Form->hidden('fabric_colour',array('value' => $new_row['FabricRangeColour']['name'],'id' => 'fabric_colour'.$key));
                                            echo $this->Form->hidden('sbos_id',array('value' => $new_row['FabricOrdering']['sbos_id'],'name' => 'sbos_id'.$key.'[]'));
                                            echo $this->Form->hidden('fabric_ordering_ids',array('value' => $id,'name' => 'fabric_ordering_ids'.$key.'[]'));
                                            echo $this->Html->image('busy.gif', array('alt' => 'Ok','id'=>$id.'fabric_widthbusy','style'=>'display:none;'));
                                            $values = array();

                                            foreach ($new_row['FabricRangeColour']['usable_width'] AS $usable_width){

                                                $values[$usable_width] = $usable_width;
                                            }

                                            echo $this->Form->input('fabric_width', array('options' => $values, 'default' => $new_row['FabricOrdering']['fabric_width'], 'label' => '', 'disabled'=> $new_row['FabricOrdering']['disabled'] , 'id'=>'form_'.$key.'fabric_width'.$new_row['FabricOrdering']['sbos_id'].'-'.$count.'-'.$order_seq, 'name' => 'length'.$key.'[]','onchange' => 'updateField(null,"'.$id.'", "fabric_width", this.value, null,null)', 'value' => $new_row['FabricOrdering']['fabric_width'] ));
                                            ?>
                                        </td>
                                        <td>
                                            <span class="ico">
                                <?php echo $this->Html->link($this->Html->image('newIco.png', array('alt' => 'Edit')), array('controller' => 'order_entry_headers', 'action' => 'edit', $new_row['FabricOrdering']['order_entry_headers_id']), array('escape' => false, 'class' => 'ico', 'title' => 'New')); ?></span>
                                            <span class="ico">
                                <?php echo $this->Html->link($this->Html->image('editIco2.png', array('alt' => 'Edit')), array('controller' => 'order_finalizeds', 'action' => 'edit', $new_row['FabricOrdering']['order_filnalizeds_id'], $new_row['FabricOrdering']['order_entry_headers_id']), array('escape' => false, 'class' => 'ico', 'title' => 'Edit')); ?></span>

                                            <span class="ico">
                                <?php echo $this->Html->link($this->Html->image('exchangeIco.png', array('alt' => 'Exchange')), array('controller' => 'order_item_workflows', 'action' => 'manage_workflows', $new_row['FabricOrdering']['order_filnalizeds_id']), array('escape' => false, 'class' => 'ico', 'title' => 'Exchange')); ?></span>

                                            <span class="ico">
                                                <a href="javascript:void(0);" onclick="javascript:getNote('<?php echo $id;?>');">
                                                    <img alt="New Note" src="<?php echo $this->webroot;?>img/new1Ico.png"></a>
                                            </span>

                                            <span class="ico">
                                                <input type="checkbox" name="send_all[]" id="form_<?php echo $key; ?>send_all<?php echo $new_row['FabricOrdering']['sbos_id'].'-'.$count.'-'.$order_seq; ?>" class="className2" value="<?php echo $id;?>"  style="vertical-align: middle;margin: 0px;">
                                            </span>

                                        </td>
                                    </tr>
                                <?php 

                                /* $count++;
                                 $quantity--;
                                      }*/
                                    // $o_e_items =  $check_order_entry_item_id;

                              $counter++;                                                      

                                //} 
                              //}


                    $cnt++;
                }

                //$header = ob_get_clean();
                //$header = str_replace('[placeholder]', $count, $header);
                // footer
                //$fabid = $fabric_ids[$cnt]['FabricOrdering']['fabric_id'];

                ?>
                                <input type="hidden" name="all_ids" id="all_ids" value="<?php echo $all_ids?>">
                                <input type="hidden" name="all_order_entry_item_ids" id="all_order_entry_item_ids" value="<?php echo $all_order_entry_item_ids?>">
                                <tr>
                                    <td colspan="10" align="right" class="greyBg">
                                        <input name="siw" class="button_gray_sm1 radious_all verd12dgray btn-dark_gray  pushme" id="<?php echo $key;?>" type="button" value="Stock">
                                        <input name="submit" class="button_gray_sm1 radious_all verd12dgray btn-dark_gray  " type="button" value="Send to Purchase Wizard" style="width:172px;" onclick="javascript:sendToPurchaseWizard('<?php echo $key;?>', this);">
                                        <input name="siw" class="button_gray_sm1 radious_all verd12dgray btn-dark_gray  sendall" id="<?php echo $key;?>" type="button" value="Send All">
                                    </td>
                                </tr>
                                </td>  

                                <?php }?>
                            </table>

现在我得到一个空白页面可能是由于我把php标签放在错误的位置?

2 个答案:

答案 0 :(得分:0)

你应该只使用一个将遍历$orderEntry["Order"]["state"]的foreach循环,例如:

<tr  id="<?php echo $new_row['Ordering']['sid'].'-'.$count.'-'.$order_seq.'_'.$colorid;?>"
<?php  
foreach($orderEntry as $item){
if ($item['Order']['state'] == Order::FINALIZED_STATE_APPROVED)
    {
         echo ' Approved';
    }
    else{ 
         echo 'Not Approved';
    }
}


  ?>  >

答案 1 :(得分:0)

<tr  id="<?php echo $new_row['Ordering']['sid'].'-'.$count.'-'.$order_seq.'_'.$colorid;?>" class="<?php echo ($orderEntry['Order']['state'] == Order::FINALIZED_STATE_APPROVED) ? 'approved' : 'unapproved' ; ?>">

我们已在此处检查$orderEntry['Order']['state']是否等于Order::FINALIZED_STATE_APPROVED,然后分配班级&#34;已批准&#34;否则指定&#34;已批准&#34;

现在,您可以为班级分配不同的颜色&#34;已批准&#34;并且&#34;未经批准&#34;所以他们看起来不一样。

修改

<?php
foreach($orderEntries as $orderEntry) {
?>
<tr  id="<?php echo $new_row['Ordering']['sid'].'-'.$count.'-'.$order_seq.'_'.$colorid;?>" class="<?php echo ($orderEntry['Order']['state'] == Order::FINALIZED_STATE_APPROVED) ? 'approved' : 'unapproved' ; ?>">
<?php
}
?>