Jump to content

Adding and Subtracting MySQL w/PHP


adgjm

Recommended Posts

I have a mysql database table with 4 fields. 1st one is ID, 2nd Name, 3rd is the number 50, 4th is the number 10.

I have a single page called "index.php". On this page, there are 4 buttons and one text field. There is a button that says "+1" and another "-1", with the third being "Subtract from 4th Field", and the fourth saying "Random". The textfield is where you input a name. When you click on the +1, it  searches for the name in the text field, and for it's third field using the number 50, it adds 1 to it. When a user clicks on Random, it takes the number in the 4th field (10) and subtracts the 50 by 10. When a user clicks on "Random", it randomly selects either +1, -1, or the number in the 4th field (10) and adds or subtracts depending on what it is.

How do I do this?
Link to comment
Share on other sites

Say I have a single PHP file that includes all those commands. How exactly does that script know what part to execute whether the +1 or -1? Could you show me an example script that shows how the system knows to execute which queries? I know you have lines of PHP to initiate the connection to MySQL, then the next is your query stored into any variable like $line and it executes it when you store it in a variable. How do you make it so that it executes only certain things if you have say 3 different queries like in my case (+1, -1, Random)?
Link to comment
Share on other sites

I'm not sure I understand... you'll only be issuing one query at a time, and then refreshing the page (according to what you said earlier).  If you need sample PHP code for executing MySQL statements, I'm sure there are plenty of such examples.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.