Jump to content

Performing calculations using php variables?


twilitegxa

Recommended Posts

How do I use php variables in JavaScript? I have data being pulled from two different tables, and what I want to do is perform a calculation when a button is clicked, then output the result. Say for example I have this:

 

 

php variable named $a

php variable named $b

 

 

So what I'd like to do is this:

 

 

When this button is clicked, subtract $b from $a, then display that result into a new variable, named $c. Can anyone help get started? I'm very new to JavaScript still.

Well, I'm not sure how to do it. What I have is a little game I'm trying to make. The player logs in, chooses their character, then goes to the page where they can fight random monsters. So the random monster is generated and then the player chooses attack. Upon pressing the attack button, I want to take the character's acv (attack combat value), which is being pulled from a table using php, and subtract that number from the monster's hp. But I don't want the monster's hp being updated in the table in the database, just on the page when they are fighting it. Then after they beat the monster (getting the hp down to zero), they will get experience and money and can choose to fight again or do something else.

 

 

So what I need to be able to do is use the php variables in my JavaScript calculations. Does that help explain what I'm trying to do any better? Can anyone help?

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.