2013-03-07 149 views
0

我有2個數組使用2 while循環來自數據庫。數組減法和賦值數組值

while($row2 = mysql_fetch_assoc($result2)) 
    { 
     $surveyscnt[$row2['user_grp_id']]=$row2['COUNT(*)']; 
    } 

    while($row3 = mysql_fetch_assoc($result3)) 
    { 
     $ndhcnt[$row3['group_id']]=$row3['headcount']; 
    } 

任何人都可以指導我怎麼做foreach循環內以下

請參考下面

foreach($surveyscnt as $node => $headcount){ 
      if($ndhcnt[$node]!=$headcount){    
       $pIdsNself = getAllParentsNself(array(**NEED TO CALL group_id**)); 
       updateRollups($pIdsNself,**NEED TO PUT THE DIFFERENCE of(COUNT*-headcount)**); 
      } 
    } 

foreach循環任何形式的幫助表示讚賞

回答

0

試試這個,如果有任何問題,請告知我。

  1. 在SQL查詢把COUNT(*) AS cnt,並在當你把它拿來喜歡:$surveyscnt[$row2['user_grp_id']]=$row2['cnt'];

  2. $ pIdsNself = getAllParentsNself(array(**NEED TO CALL group_id**));這裏$節點的組ID(根據您的編碼),所以行更改爲getAllParentsNself(array($node));

  3. updateRollups($pIdsNself,**NEED TO PUT THE DIFFERENCE of(COUNT*-headcount)**);,這裏有兩個計數*和頭數量,使得THI線將updateRollups($pIdsNself,($headcount-$ndhcnt[$node]));

+0

謝謝男人:)但不是$總人數,我需要把$ surveyscnt [$ node] – Justin 2013-03-07 05:38:59