php Foreach nested loop and array reset by itself in the middle -
i have php code, 3 foreach loops , last 1 or maybe second 1 causing array reset @ point , can't find why?
php code:
<?php $months = range(1,12); foreach($accountsubs $subs){ ?> <tr style="display:none;" class="tablerow paddingzero childoverview <?php echo $classj;?>"> <td width="40" align="center"><?php echo $subs['codename'];?></td> <td><?php echo $subs['subclass'];?></td> <?php $itemcodes = $db->fetch_all_array("select * bg_itemcodes accountclass='".$subs['id']."' , cparent = '".$ac['id']."' "); $counter = 1; foreach($itemcodes $code){ foreach($months $ms){ echo $counter++; $makedate = strtotime($jdate.'-'.$ms.'-1'); $sdebits = $db->single("select sum($currency) $currency bg_journal factory='$jfactory' , section = '".$ac['id']."' , record_section !='record' , itemcode = '".$code['id']."' , from_unixtime(jtime, '%y%m') = '".date('ym',$makedate)."' , inouts = 'out' "); $scredits = $db->single("select sum($currency) $currency bg_journal factory='$jfactory' , section = '".$ac['id']."' , record_section !='record' , itemcode = '".$code['id']."' , from_unixtime(jtime, '%y%m') = '".date('ym',$makedate)."' , inouts = 'in' "); $totalsdc = $scredits[$currency] - $sdebits[$currency]; ?> <td class="alignright"><?php echo correctvalue($totalsdc,$jcurrency);?></td> <?php }// foreach months }// foreach item codes ?> </tr> <?php }// foreach sub class
and here view source can see how resets on 3rd loop escapes counter on second loop.
<tr style="display:none;" class="tablerow paddingzero childoverview showclass_8"> <td width="40" align="center">103</td> <td>other sales</td> 1 <td class="alignright"></td> 2 <td class="alignright"></td> 3 <td class="alignright"></td> 4 <td class="alignright"></td> 5 <td class="alignright"></td> 6 <td class="alignright"></td> 7 <td class="alignright"></td> 8 <td class="alignright"><span style="float:left; color:#444;">؋</span>1,000.00</td> 9 <td class="alignright"></td> 10 <td class="alignright"></td> 11 <td class="alignright"></td> 12 <td class="alignright"></td> </tr> <tr class="tablerow paddingzero overviewtitle"> <td align='center'><strong>400</strong></td> <td style="text-transform:capitalize;">expenses <a href="javascript:void(0);" data-id="showclass_10" class="addplus plus">+</a></td> <td class="alignright"><strong></strong></td> <td class="alignright"><strong></strong></td> <td class="alignright"><strong></strong></td> <td class="alignright"><strong></strong></td> <td class="alignright"><strong></strong></td> <td class="alignright"><strong></strong></td> <td class="alignright"><strong></strong></td> <td class="alignright"><strong><span style="float:left; color:#444;">؋</span>-59,200.00</strong></td> <td class="alignright"><strong></strong></td> <td class="alignright"><strong></strong></td> <td class="alignright"><strong></strong></td> <td class="alignright"><strong></strong></td> </tr> <tr style="display:none;" class="tablerow paddingzero childoverview showclass_10"> <td width="40" align="center">401</td> <td>raw materials</td> 1 <td class="alignright"></td> 2 <td class="alignright"></td> 3 <td class="alignright"></td> 4 <td class="alignright"></td> 5 <td class="alignright"></td> 6 <td class="alignright"></td> 7 <td class="alignright"></td> 8 <td class="alignright"></td> 9 <td class="alignright"></td> 10 <td class="alignright"></td> 11 <td class="alignright"></td> 12 <td class="alignright"></td> 13 <td class="alignright"></td> 14 <td class="alignright"></td> 15 <td class="alignright"></td> 16 <td class="alignright"></td> 17 <td class="alignright"></td> 18 <td class="alignright"></td> 19 <td class="alignright"></td> 20 <td class="alignright"><span style="float:left; color:#444;">؋</span>-58,900.00</td> 21 <td class="alignright"></td> 22 <td class="alignright"></td> 23 <td class="alignright"></td> 24 <td class="alignright"></td> </tr> <tr style="display:none;" class="tablerow paddingzero childoverview showclass_10"> <td width="40" align="center">402</td> <td>office supplies</td> 1 <td class="alignright"></td> 2 <td class="alignright"></td> 3 <td class="alignright"></td> 4 <td class="alignright"></td> 5 <td class="alignright"></td> 6 <td class="alignright"></td> 7 <td class="alignright"></td> 8 <td class="alignright"><span style="float:left; color:#444;">؋</span>-200.00</td> 9 <td class="alignright"></td> 10 <td class="alignright"></td> 11 <td class="alignright"></td> 12 <td class="alignright"></td> </tr>
there no such thing array reset occurring here. if inspect code can see variable $counter
being initialized/reinitialized before itemcode. hence, logical explanation sub category raw materials
return 2 object query:
$itemcodes = $db->fetch_all_array("select * bg_itemcodes accountclass='".$subs['id']."' , cparent = '".$ac['id']."' ");
ie. 2*12 time increment $counter
equal 24.
you might want group each expense item code subcategory.
Comments
Post a Comment