RON_ron Posted November 17, 2010 Share Posted November 17, 2010 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 More sharing options...
jcbones Posted November 17, 2010 Share Posted November 17, 2010 It works as coded. If you need additional help you will need to specify how you want the calculations to work. Link to comment https://forums.phpfreaks.com/topic/218912-calculation-with-if-statement/#findComment-1135313 Share on other sites More sharing options...
RON_ron Posted November 17, 2010 Author Share Posted November 17, 2010 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'] Link to comment https://forums.phpfreaks.com/topic/218912-calculation-with-if-statement/#findComment-1135318 Share on other sites More sharing options...
doni49 Posted November 17, 2010 Share Posted November 17, 2010 Is this code copy/pasted directly from your php file? If so, it should be throwing errors. The echo statements don't have dollar signs in front of the vars. echo(udatedValue); Should be: echo($udatedValue); Link to comment https://forums.phpfreaks.com/topic/218912-calculation-with-if-statement/#findComment-1135335 Share on other sites More sharing options...
RON_ron Posted November 17, 2010 Author Share Posted November 17, 2010 Thanks Don!! Link to comment https://forums.phpfreaks.com/topic/218912-calculation-with-if-statement/#findComment-1135336 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.