Jump to content

using javascript on MySQL data


kanala

Recommended Posts

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

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

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

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

Archived

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

×
×
  • Create New...