Okay... I have a function that returns the highest value from an array that is creates form our DB. It work fine until I try to loop through. It will only return the first value.
Here's my function
function getBest($best2){
require('../../xxxx/xxxxx.inc');
$d3 = array();
$sql22 = "SELECT * FROM files.drillXX
WHERE D3D2A = '".$best2."'
OR D3D2B = '".$best2."'
OR D3D2C = '".$best2."'";
$res22 = db2_exec($i5db2,$sql22)
or die('ERROR DRILL 3: ' . db2_stmt_errormsg());
while($row22 = db2_fetch_assoc($res22)){
$d3[] = $row22['D3ID'];
}
$d4 = array();
$c = 1;
foreach($d3 as $key2=>$v2){
$sql3 = "SELECT * FROM files.drillXX
JOIN files.itemsale on D4ITEM = SITEM
WHERE D4D3A = '".$v2."'
OR D4D3B = '".$v2."'
ORDER BY SCYSAL DESC FETCH FIRST 1 ROW ONLY";
$res2 = db2_exec($i5db2,$sql3)
or die('ERROR DRILL 4: ' . db2_stmt_errormsg());
while($row3 = db2_fetch_assoc($res2)){
$d4[$c][] = $row3['D4ITEM'];
$d4[$c][] = $row3['SCYSAL'];
$c++;
}
}
function bestSeller($a, $b)
{
if ($a["1"] == $b["1"]) {
return 0;
}
return ($a["1"] < $b["1"])
? -1
: 1;
}
usort($d4, "bestSeller");
$max = $d4[count($d4)-1]["1"];
$arr = array();
foreach($d4 as $key=>$value){
if($value[1] == $max){
$arr[] = $value[0];
$arr[] = $value[1];
}
}
return $arr[0];
}
Here's the loop that I attempt that only returns one value and will not retrieve the rest.
$x = array('59','60', '7', '10');
foreach($x as $v){
$w = getBest($v);
echo "<pre>";
echo $w;
}
Any insight would be appreciated.
j