Jump to content

Calculation with if statement


RON_ron

Recommended Posts

Please help me calculate this according to the "if" condition.

 

$scoreM['newtag'] + $scoreU['newPrice']

 

$SomeVar = 'currentPrice';
$queryU =  "SELECT * FROM db1 WHERE bookprice = '".$SomeVar."'";
$resultU = mysql_query($queryU);
$scoreU = mysql_fetch_assoc($resultU);
echo $scoreU['newPrice'];
echo $scoreU['weeklyScr'];
echo $scoreU['priceX'];

////
$WinVar = 'additionalAmount';
$query =  "SELECT * FROM db2 WHERE booklist = '".$WinVar."'";
$result = mysql_query($query);
$scoreM = mysql_fetch_assoc($result);
echo $scoreM['newtag'];  
echo $scoreM['priceY']; 

if($scoreU['priceX']== $scoreM['priceY'])
{
$udatedValue = ($scoreM['newtag'] - $scoreU['newPrice']);
echo(udatedValue);
}
else{
$udatedValue = ($scoreM['newtag'] + $scoreU['newPrice']);
echo(udatedValue);
}

Link to comment
https://forums.phpfreaks.com/topic/218912-calculation-with-if-statement/
Share on other sites

Thanks jcbones. But the code did not give me the results I wanted. This echos "udatedValue" nothing else.

 

Here's what I'm trying to achieve.

 

I want to check if the $scoreM['newtag'] and $scoreU['newPrice'] are the same.

 

If it is similar

 

then I want to get the difference between $scoreM['newtag'] and $scoreU['newPrice']

 

if it's not similar

 

then I want to get the total between $scoreM['newtag'] and $scoreU['newPrice']

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.