如果我在數組中運行一個值,那麼結果是正確的,如果我運行多個值,結果是價格是不正確的,就像它已經與值的地方弄亂了代碼? ?幫助讚賞陣列和每個迴路問題
$dido=array('42204131','22204131'); foreach($dido as $did): $query = "select * from dispatch,link where lid=dlid and did=$did"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ $vanc1=$row['vanc1']; $vanc2=$row['vanc2']; $vanc3=$row['vanc3']; $vanc4=$row['vanc4']; $vanc5=$row['vanc5']; $anc1=$row['anc1']; $anc2=$row['anc2']; $anc3=$row['anc3']; $anc4=$row['anc4']; $anc5=$row['anc5']; // price anc1 $querypanc1 = "select pprice from products where pid=$anc1"; $resultpanc1 = mysql_query($querypanc1); while($row = mysql_fetch_array($resultpanc1)) { $priceanc1=$row[pprice]; $tpriceanc1=$vanc1*$priceanc1; } // price anc2 $querypanc2 = "select pprice from products where pid=$anc2"; $resultpanc2 = mysql_query($querypanc2); while($row = mysql_fetch_array($resultpanc2)) { $priceanc2=$row[pprice]; $tpriceanc2=$vanc2*$priceanc2; } // price anc3 $querypanc3 = "select pprice from products where pid=$anc3"; $resultpanc3 = mysql_query($querypanc3); while($row = mysql_fetch_array($resultpanc3)) { $priceanc3=$row[pprice]; $tpriceanc3=$vanc3*$priceanc3; } // price anc4 $querypanc4 = "select pprice from products where pid=$anc4"; $resultpanc4 = mysql_query($querypanc4); while($row = mysql_fetch_array($resultpanc4)) { $priceanc4=$row[pprice]; $tpriceanc4=$vanc4*$priceanc4; } // price anc5 $querypanc5 = "select pprice from products where pid=$anc5"; $resultpanc5 = mysql_query($querypanc5); while($row = mysql_fetch_array($resultpanc5)) { $priceanc5=$row[pprice]; $tpriceanc5=$vanc5*$priceanc5; } $gtprice=$tpriceanc1+$tpriceanc2+$tpriceanc3+$tpriceanc4+$tpriceanc5; $qrygt="UPDATE dispatch SET gtprice=$gtprice WHERE did=$did"; [email protected]_query($qrygt); } endforeach;
不能相信沒有人調升該O-O –
感謝...沒想到做一個函數 – user2288221