adgjm Posted October 15, 2006 Share Posted October 15, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/24028-adding-and-subtracting-mysql-wphp/ Share on other sites More sharing options...
fenway Posted October 15, 2006 Share Posted October 15, 2006 This has nothing to do with MySQL...? Quote Link to comment https://forums.phpfreaks.com/topic/24028-adding-and-subtracting-mysql-wphp/#findComment-109179 Share on other sites More sharing options...
adgjm Posted October 15, 2006 Author Share Posted October 15, 2006 It does. I do not know how to make multiple connections to SQL and how to affect tables in the way I mentioned in my first post. Please help. Quote Link to comment https://forums.phpfreaks.com/topic/24028-adding-and-subtracting-mysql-wphp/#findComment-109191 Share on other sites More sharing options...
fenway Posted October 15, 2006 Share Posted October 15, 2006 If you want to do this in real-time, you'll need some sort of asynchronous engine (e.g. AJAX). The individual statements (adding one, substracting one, subtract A-B, etc.) shouldn't be an issue. Quote Link to comment https://forums.phpfreaks.com/topic/24028-adding-and-subtracting-mysql-wphp/#findComment-109222 Share on other sites More sharing options...
adgjm Posted October 16, 2006 Author Share Posted October 16, 2006 I just need to know the individual statements. This does not need to be done in realtime. I am fine if it refreshes the page after you click on +1 or -1. Quote Link to comment https://forums.phpfreaks.com/topic/24028-adding-and-subtracting-mysql-wphp/#findComment-109236 Share on other sites More sharing options...
fenway Posted October 16, 2006 Share Posted October 16, 2006 UPDATE yourTable SET yourField = yourField +1 WHERE name = 'yourName' Quote Link to comment https://forums.phpfreaks.com/topic/24028-adding-and-subtracting-mysql-wphp/#findComment-109239 Share on other sites More sharing options...
adgjm Posted October 17, 2006 Author Share Posted October 17, 2006 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)? Quote Link to comment https://forums.phpfreaks.com/topic/24028-adding-and-subtracting-mysql-wphp/#findComment-109849 Share on other sites More sharing options...
fenway Posted October 17, 2006 Share Posted October 17, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/24028-adding-and-subtracting-mysql-wphp/#findComment-110106 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.