kanala Posted July 19, 2007 Share Posted July 19, 2007 I have 2 fields on my MySQL table which are Price and OldPrice.I need to work out the price difference between them by subtracting the Price from the OldPrice (OldPrice-Price) using javascript.Using $row['OldPrice'] and $row['Price'] or something, how would I subtract them using javascript then put them onto the page using "document.write" (or something similar). Link to comment Share on other sites More sharing options...
justsomeguy Posted July 19, 2007 Share Posted July 19, 2007 Why do you need to use Javascript? There's nothing special about subtraction, a normal subtraction operator works just fine. Link to comment Share on other sites More sharing options...
jhecht Posted July 19, 2007 Share Posted July 19, 2007 Yeah, to re-iterate what was already said, you don't need javascript to do that. You can just use PHP. $difference = $row['oldPrice'] - $row['price'];//If oldPrice was 20, and price was 15, the difference would be 5(dollars, just without the $ sign. You would have to add that in later). Javascript isn't needed for something like that. Link to comment Share on other sites More sharing options...
kanala Posted July 19, 2007 Author Share Posted July 19, 2007 OH lol, I never knew PHP could do that, thanks. Link to comment Share on other sites More sharing options...
jhecht Posted July 19, 2007 Share Posted July 19, 2007 PHP can do just about anything Javascript can do, if not more(since PHP can access files on the user's computer through the input type="file" method. Link to comment Share on other sites More sharing options...
justsomeguy Posted July 19, 2007 Share Posted July 19, 2007 PHP is a modern, Turing-complete language. Arithmetic operations like addition and subtraction are the basic operations of a CPU, I'm not aware of a single programming language that cannot do arithmetic. It would probably be good for you to read at least the langage reference portion of the PHP manual:http://www.php.net/manual/en/langref.php Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.