how to manipulate an array???
Moderator: General Moderators
i get unsupported operand types...
the error pointed at
$minDownTime=$dt1/$dt2;
Code: Select all
while($periksa=mysql_fetch_array($viewCheck))
{
$MTTF=$_POST["MTTF"];
$bd=$_POST["purataMasaBD"];
$pb=$_POST["purataMasaPPM"];
$bilInspection=$periksa["n"];
$bt1=exp(-$MTTF*$bilInspection);
$bt2=$bt1/($MTTF/$bilInspection);
$bt3=1-$bt2;
//$gagal=explode(',', $_POST["gagal"]);
//$dt1=$gagal*$bilInspection*$bd*$bt3+$pb;
foreach(explode(',', $_POST['gagal']) as $gag){
$dt1[]=($gag*$bilInspection*$bd*$bt3)+$pb;
}
$dt2=$bilInspection+$pb;
$minDownTime=$dt1/$dt2;
$minDownTime1=number_format($minDownTime, 5, '.', '');
echo "<pre>";
print_r($dt1);
echo "</pre>";
$SQLupd=mysql_query("UPDATE mindowntime SET Dn = '$minDownTime1' where n='$bilInspection'");
}$minDownTime=$dt1/$dt2;
$minDownTime=$dt1/$dt2;
$dt1 is now an array ... so you can't divide it.
Just so you're clear what's happening ..
you are posting from a form, a string that might look like '1,2,3,4'
Then you take each of those numbers in turn and do a calculation on them, storing the result in another array, $dt1.
So instead of $minDownTime=$dt1/$dt2; i'm guessing you want $minDownTime=array_sum($dt1)/$dt2; which will first add up all those individual calculations and divide the sum of them by $dt2.
$dt1 is now an array ... so you can't divide it.
Just so you're clear what's happening ..
you are posting from a form, a string that might look like '1,2,3,4'
Then you take each of those numbers in turn and do a calculation on them, storing the result in another array, $dt1.
So instead of $minDownTime=$dt1/$dt2; i'm guessing you want $minDownTime=array_sum($dt1)/$dt2; which will first add up all those individual calculations and divide the sum of them by $dt2.
this is my code:
all of them is in the while loop...
what i want to do is the array posted from the first page will be stored in $gag...
and lets say $gag=1,2,3...12
and in the first loop,
$dt1[]=($gag*$bilInspection*$bd*$bt3)+$pb;
will be executed with $gag=1,
and one the second loop,
$dt1[]=($gag*$bilInspection*$bd*$bt3)+$pb;
will be executed with $gag=2,
and so on...
do u get it???
Code: Select all
while($periksa=mysql_fetch_array($viewCheck))
{
$MTTF=$_POST["MTTF"];
$bd=$_POST["purataMasaBD"];
$pb=$_POST["purataMasaPPM"];
$bilInspection=$periksa["n"];
$bt1=exp(-$MTTF*$bilInspection);
$bt2=$bt1/($MTTF/$bilInspection);
$bt3=1-$bt2;
//$gagal=explode(',', $_POST["gagal"]);
//$dt1=$gagal*$bilInspection*$bd*$bt3+$pb;
foreach(explode(',', $_POST['gagal']) as $gag){
$dt1[]=($gag*$bilInspection*$bd*$bt3)+$pb;
}
$dt2=$bilInspection+$pb;
$minDownTime=$dt1/$dt2;
$minDownTime1=number_format($minDownTime, 5, '.', '');
echo "<pre>";
print_r($dt1);
echo "</pre>";
$SQLupd=mysql_query("UPDATE mindowntime SET Dn = '$minDownTime1' where n='$bilInspection'");
}what i want to do is the array posted from the first page will be stored in $gag...
and lets say $gag=1,2,3...12
and in the first loop,
$dt1[]=($gag*$bilInspection*$bd*$bt3)+$pb;
will be executed with $gag=1,
and one the second loop,
$dt1[]=($gag*$bilInspection*$bd*$bt3)+$pb;
will be executed with $gag=2,
and so on...
do u get it???
Nope, still don't get it. That's exactly what your code should be doing now, what i'm unclear about is what you want to do with each of the values .. ($gag*$bilInspection*$bd*$bt3)+$pb; ... it 'sounds' like you want ..
but again, i'm guessing as i'm still unclear..sorry. If i've got it wrong then paste some code that shows how it should work .. even if it doesn't it will give us an idea of what you are aiming for exactly.
Code: Select all
{
$MTTF=$_POST["MTTF"];
$bd=$_POST["purataMasaBD"];
$pb=$_POST["purataMasaPPM"];
$bilInspection=$periksa["n"];
$bt1=exp(-$MTTF*$bilInspection);
$bt2=$bt1/($MTTF/$bilInspection);
$bt3=1-$bt2;
foreach(explode(',', $_POST['gagal']) as $gag){
$dt1=($gag*$bilInspection*$bd*$bt3)+$pb;
$dt2=$bilInspection+$pb;
$minDownTime=$dt1/$dt2;
$minDownTime1=number_format($minDownTime, 5, '.', '');
echo "<pre>";
print_r($dt1);
echo "</pre>";
$SQLupd=mysql_query("UPDATE mindowntime SET Dn = '$minDownTime1' where n='$bilInspection'");
}
}wow...it shows this:
WITH 12 set of that!!
and the
0.032
0.036
0.032
0.033
0.032
0.167
0.000
0.065
0.067
0.032
0.033
0.000
is exactly the correct value..
but why it appears in 12 set???
Code: Select all
string(71) "0.032,0.036,0.032,0.033,0.032,0.167,0.000,0.065,0.067,0.032,0.033,0.000"
0.032
0.036
0.032
0.033
0.032
0.167
0.000
0.065
0.067
0.032
0.033
0.000and the
0.032
0.036
0.032
0.033
0.032
0.167
0.000
0.065
0.067
0.032
0.033
0.000
is exactly the correct value..
but why it appears in 12 set???
yup...
but i wonder why its in 12 set....
the true output is:
but i wonder why its in 12 set....
the true output is:
Code: Select all
string(71) "0.032,0.036,0.032,0.033,0.032,0.167,0.000,0.065,0.067,0.032,0.033,0.000"
0.032
0.036
0.032
0.033
0.032
0.167
0.000
0.065
0.067
0.032
0.033
0.000
string(71) "0.032,0.036,0.032,0.033,0.032,0.167,0.000,0.065,0.067,0.032,0.033,0.000"
0.032
0.036
0.032
0.033
0.032
0.167
0.000
0.065
0.067
0.032
0.033
0.000
string(71) "0.032,0.036,0.032,0.033,0.032,0.167,0.000,0.065,0.067,0.032,0.033,0.000"
0.032
0.036
0.032
0.033
0.032
0.167
0.000
0.065
0.067
0.032
0.033
0.000
string(71) "0.032,0.036,0.032,0.033,0.032,0.167,0.000,0.065,0.067,0.032,0.033,0.000"
0.032
0.036
0.032
0.033
0.032
0.167
0.000
0.065
0.067
0.032
0.033
0.000
string(71) "0.032,0.036,0.032,0.033,0.032,0.167,0.000,0.065,0.067,0.032,0.033,0.000"
0.032
0.036
0.032
0.033
0.032
0.167
0.000
0.065
0.067
0.032
0.033
0.000
string(71) "0.032,0.036,0.032,0.033,0.032,0.167,0.000,0.065,0.067,0.032,0.033,0.000"
0.032
0.036
0.032
0.033
0.032
0.167
0.000
0.065
0.067
0.032
0.033
0.000
string(71) "0.032,0.036,0.032,0.033,0.032,0.167,0.000,0.065,0.067,0.032,0.033,0.000"
0.032
0.036
0.032
0.033
0.032
0.167
0.000
0.065
0.067
0.032
0.033
0.000
string(71) "0.032,0.036,0.032,0.033,0.032,0.167,0.000,0.065,0.067,0.032,0.033,0.000"
0.032
0.036
0.032
0.033
0.032
0.167
0.000
0.065
0.067
0.032
0.033
0.000
string(71) "0.032,0.036,0.032,0.033,0.032,0.167,0.000,0.065,0.067,0.032,0.033,0.000"
0.032
0.036
0.032
0.033
0.032
0.167
0.000
0.065
0.067
0.032
0.033
0.000
string(71) "0.032,0.036,0.032,0.033,0.032,0.167,0.000,0.065,0.067,0.032,0.033,0.000"
0.032
0.036
0.032
0.033
0.032
0.167
0.000
0.065
0.067
0.032
0.033
0.000
string(71) "0.032,0.036,0.032,0.033,0.032,0.167,0.000,0.065,0.067,0.032,0.033,0.000"
0.032
0.036
0.032
0.033
0.032
0.167
0.000
0.065
0.067
0.032
0.033
0.000
string(71) "0.032,0.036,0.032,0.033,0.032,0.167,0.000,0.065,0.067,0.032,0.033,0.000"
0.032
0.036
0.032
0.033
0.032
0.167
0.000
0.065
0.067
0.032
0.033
0.000