1

I get price from database with 9xx items. I add this on show items page. Using Foreach $rows=$row. vprice is my sellingprice and dprice is my dealerprice

$commisionrate = 30;
$commisionfee  = 100;
$fee  = $row['dprice'] + $commisionfee;//+100
$x = $row['dprice'];
$y = $x * $commisionrate / 100;
$z = $x + $y;
$rate = $z;//(100*30%)+100
if (($rate > $row['vprice']) && ($fee < $row['vprice'])){
    echo $fee;
}elseif (($fee > $row['vprice']) && ($rate < $row['vprice'])){
    echo $rate;
}elseif ($row['dprice']=$row['vprice']){
    echo $row['dprice'];
}

when I recheck all, I found that few items of $row['dprice'] is not counted and still show by old price. Example that is false: I found vprice is 188 with 80 dprice after calculate should be 104 but not changing with still stay on 80.

ekad
  • 14,436
  • 26
  • 44
  • 46
philip ngu
  • 59
  • 1
  • 1
  • 7

1 Answers1

1
$commisionrate = 30;
$commisionfee  = 100;
$fee  = $row['dprice'] + $commisionfee;//+100
$x = $row['dprice'];
$y = $x * $commisionrate / 100;
$rate = $x + $y;

// You don't need to put nested brackets, it very simple condition    
if ($rate > $row['vprice'] && $fee < $row['vprice']){
    echo "fee: " . $fee; //add some hint words, so you know which condition fires

// You don't need to put nested brackets, it very simple condition
} elseif ($fee > $row['vprice'] && $rate < $row['vprice']) {
    echo "rate: " . echo $rate;

// USE double `==`, because when single `=` used, the condition always returns true and you're confused by your result
} elseif ($row['dprice'] == $row['vprice']) { 
    echo "row[\'dprice\']: " . $row['dprice'];

// add last else
} else {
   // this is helpful for debugging of your possible output, regardless you are awaiting some output here
}
pedrouan
  • 12,762
  • 3
  • 58
  • 74
  • Hi. Im not confuse for the result. I only forget to add 1 more condition that if rate and fee is lower than vprice then will choose to use rate price. – philip ngu Sep 17 '16 at 09:20