Hello All, Ive been hurting my head with this one all day. I am trying to load an array of numbers. If it is the first add to my workspace, then just add them all. If it is the second time, combine the numbers of value that have the same ID. Post is my code below. The problem is when I load the values the first time, they become doubled. But if i clear the workspace and add again, they add correctly. Thanks for looking.
$assigned_to = $_POST['check'];
//Here we're temporarily localizing the session values
//the count is used to stack values onto the existing values
$workspace = $_SESSION['workspace'];
$count = $_SESSION['count'];
$count2 = 0;
for($i=0; $i<count($assigned_to); $i++)
{
$file = "http://xxxxxx/".trim($assigned_to[$i]).".csv";
$data_array = file($file);
$test = 0;
for($j=0; $j < count($data_array); $j++)
{
$data_line = $data_array[$j];
$temp_array = explode(',',$data_line);
$temp_array2[$count2][0] = $temp_array[9];
$temp_array2[$count2][1] = $temp_array[0];
$temp_array2[$count2][2] = $temp_array[2];
$temp_array2[$count2][3] = $temp_array[3];
$temp_array2[$count2][4] = $temp_array[4];
$temp_array2[$count2][5] = $temp_array[5];
$temp_array2[$count2][6] = $temp_array[6];
$temp_array2[$count2][7] = $temp_array[7];
$temp_array2[$count2][8] = $temp_array[8];
$temp_array2[$count2][9] = ($temp_array[8]/$temp_array[4]);
$workspace[$count2 + $count] = $temp_array[9];
$just_in[$count2] = $temp_array[9];
$count2++;
}
}
//print_r($temp_array2);
$temp = array_unique($workspace);
$temp2 = array_merge($temp);
$temp3 = array_unique($just_in);
$temp4 = array_merge($temp3);
//print_r($temp);
$count = count($temp2);
$_SESSION['workspace'] = $temp2;
$_SESSION['count'] = $count;
$work_dashboard = $_SESSION['work_dash'];
//if there were initially no values in $_SESSION['work_dash'],
//it revealed a 1 for count. Apparently it gets passed in as an empty
//string. Here's the fix.
if(is_string($work_dashboard))
{
$my_count = 0;
}
else
{
$my_count = count($work_dashboard);
}
//echo $my_count;
if($my_count > 0)
{
for($j=0; $j<count($temp4); $j++)
{
$finder = $temp4[$j];
//print_r($work_dashboard);
for($k=0; $k<count($work_dashboard); $k++)
{
$tempval1 = 0;
$tempval2 = 0;
$tempval3 = 0;
$tempval4 = 0;
$tempval5 = 0;
$matcher = $work_dashboard[$k];
$temp_dash = explode(",", $work_dashboard[$k]);
$tempval1= $temp_dash[4];
$tempval2= $temp_dash[5];
$tempval3= $temp_dash[6];
$tempval4= $temp_dash[7];
$tempval5= $temp_dash[8];
//print_r($work_dashboard[$k]);
//echo "<br>";
if(eregi($finder, $matcher))
{
$tempval = array();
for($l=0; $l<count($temp_array2); $l++)
{
if(trim($temp_dash[0]) == trim($temp_array2[$l][0]))
{
$tempval[0]= $temp_array2[$l][0];
$tempval[1]= $temp_array2[$l][1];
$tempval[2]= $temp_array2[$l][2];
$tempval[3]= $temp_array2[$l][3];
$tempval[4]= $tempval1 + $temp_array2[$l][4];
$tempval[5]= $tempval2 + $temp_array2[$l][5];
$tempval[6]= $tempval3 + $temp_array2[$l][6];
$tempval[7]= $tempval4 + $temp_array2[$l][7];
$tempval[8]= $tempval5 + $temp_array2[$l][8];
$tempval[9]= $temp_array2[$l][9];
}
}
$work_dashboard[$k] = implode(",",$tempval);
}
}
}
}
else
{
for($l=0; $l<count($temp_array2); $l++)
{
$work_dashboard[$my_count] = implode(",",$temp_array2[$l]);
$my_count++;
}
}
$_SESSION['work_dash'] = $work_dashboard;