次のような値を含む配列 year_values があります
$year_values = array();
foreach($year_strings as $str) {
$year_values[] = explode(",", $str);
}
次に、データベースからいくつかの値を抽出するためのクエリを適用します
$sql = "SELECT inventory.holdingcost as holdingcost,
inventory.ordercost as ordercost, inventory.unitprice as unitprice,
inventory.lead_time as lead_time, items.id as iid
FROM inventory, items
WHERE inventory.item_name = items.item_name";
mysql_error();
$result = mysql_query($sql);
foreach($year_values as $vals) {
while ($row = mysql_fetch_row($result)) {
$w = $row[2];
$e = $row[0];
$r = $row[1];
$tt = $row[3];
$eo = sqrt(2 * $vals[5] * $r / ($e * $w));
$eoq = round($eo, 1);
$ro = $vals[5] / 360;
$rop = round($ro * $tt);
$op = round($vals[5] / $eoq, 1);
$cc = round(89 / $op);
$h = round((($eoq * $e * $w) / 2), 2);
$o = round((($r * $vals[5]) / $eoq), 2);
$z = round($h + $o, 2);
}
}
上記の foreach while ループを使用すると、最初の値が$year_values
$vals[5] として取得され、 array のすべての値に対して while 内で計算が必要になります$year_values
。
それを修正する方法は?
value1、つまり現在 $val[5] で繰り返しが発生しています:
Value1 Value 2 Value 3
199 202 0.25
199 205 0.25
199 210 0.25
199 230 0.25
1698 202 0.25
1698 205 0.25
1698 210 0.25
1698 230 0.25
代わりに、値を次のように表示したい
Value1 Value 2 Value 3
199 202 0.25
1698 205 0.25
15 210 0.25
971 230 0.25