$result =0;
if ($id_marca!=1) {
$result = $result + $vl_max*$pares; // id_marca = 22 [ 38 pares * 1.451 = 55.14 ]
}
elseif ($id_marca=='1'){
$result = $result + $vl_min*$pares; ///id_marca = 1 [ 36 pares * 1.392 = 50.15 ]
}
else {
$result ='';
}
$result;
Hello, I need Help.
with above script, I´m receiving the $result two values (55.14 & 50.15).
So, I want to the sum the $result = (105.29).
Thank you!!
jorgeftz
0
Newbie Poster
Recommended Answers
Jump to PostIf you want both values totalled then you don't want the IF/ELSE structure because that is the reason only one calculation is running (whether $id_marca equals 1 or not).
Depending on your exact requirements you would be better off to store each calculation into two different result variables and then …
Jump to PostYou still have the if/else clause in there.
If $id_marca != 1 the resultMax is calculated otherwise it is 0.
If $id_marca = 1 then resultMin is calculated otherwise it is 0;Take out that entire if/else block and just have the two calcualtion lines. Then $resultMax and $resultMin will …
Jump to PostSorry, I may not be understanding exactly what you need then. In your initial post you said you needed to get 105.29, the sum of 55.14 & 50.15 (the max and min calculation I'm assuming).
But if you're getting just one value OR the other then you never have two …
Jump to PostOK, I see now. In that case define $resultMax and $resultMin before the FOR loop, so they aren't reset/overwritten on subsequent loops, and use the if/else to tally up totals
$resultMax = $resultMax + ($vl_max x $pares);That will give you a running total of $resultMax and $resultMin that can …
Jump to PostIn your code smaple you have the start of the FOR loop but I can't see where it ends. Is you final echo ouside of the FOR loop? If it is then you should only see one echo which should, hopefully, be the total.
All 19 Replies
hericles
289
Master Poster
Featured Poster
jorgeftz
0
Newbie Poster
hericles
289
Master Poster
Featured Poster
jorgeftz
0
Newbie Poster
hericles
289
Master Poster
Featured Poster
jorgeftz
0
Newbie Poster
hericles
289
Master Poster
Featured Poster
jorgeftz
0
Newbie Poster
jorgeftz
0
Newbie Poster
hericles
289
Master Poster
Featured Poster
jorgeftz
0
Newbie Poster
diafol
jorgeftz
0
Newbie Poster
diafol
jorgeftz
0
Newbie Poster
jorgeftz
0
Newbie Poster
jorgeftz
0
Newbie Poster
jorgeftz
0
Newbie Poster
diafol
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.