Leveecius Posted November 4, 2009 Share Posted November 4, 2009 Hey guys, I have a quick question. If I want to make a way for people to pay for health in my game, how would I go about coding that? Would be like this? ($purchace = 1000000) == ($health+1) Would it be something like that? Quote Link to comment https://forums.phpfreaks.com/topic/180314-coding-question/ Share on other sites More sharing options...
ram4nd Posted November 4, 2009 Share Posted November 4, 2009 probably not, you give so few information Quote Link to comment https://forums.phpfreaks.com/topic/180314-coding-question/#findComment-951205 Share on other sites More sharing options...
Leveecius Posted November 4, 2009 Author Share Posted November 4, 2009 Well I can put the mysql scripts and stuff like that, but I haven't written it yet. Let me write an example and post it really quick Quote Link to comment https://forums.phpfreaks.com/topic/180314-coding-question/#findComment-951211 Share on other sites More sharing options...
Leveecius Posted November 4, 2009 Author Share Posted November 4, 2009 Here is my example: <?php $purchase = rows['money']-1000000; $heal = rows['health']+1; mysql_query("SELECT * FROM users WHERE username='$username'"); mysql_query("SET * FROM users WHERE health='$heal', money='$purchase'"); >? Quote Link to comment https://forums.phpfreaks.com/topic/180314-coding-question/#findComment-951214 Share on other sites More sharing options...
Leveecius Posted November 5, 2009 Author Share Posted November 5, 2009 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/180314-coding-question/#findComment-951849 Share on other sites More sharing options...
kickstart Posted November 5, 2009 Share Posted November 5, 2009 Hi What is it you are trying to do? Where are you trying to add health / charge money? All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/180314-coding-question/#findComment-951853 Share on other sites More sharing options...
Leveecius Posted November 5, 2009 Author Share Posted November 5, 2009 I haven't added it yet. I'm trying to make it so that in the hospital in my game, they have the option of buying health rather than stay in the hospital for anytime. Quote Link to comment https://forums.phpfreaks.com/topic/180314-coding-question/#findComment-951873 Share on other sites More sharing options...
kickstart Posted November 5, 2009 Share Posted November 5, 2009 Hi If health and money are both on the same table then it is merely a simple update statement Something like UPDATE users set money = money - 1000000, health = health + 1 WHERE username='$username' AND money > 1000000 All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/180314-coding-question/#findComment-951878 Share on other sites More sharing options...
Leveecius Posted November 5, 2009 Author Share Posted November 5, 2009 Well here is the scripting I have for it right now, it doesn't really work. It just displays the echo, but doesn't do anything else. <?php mysql_query("SELECT * FROM users WHERE username='$username'"); $purchase = ($cash-10000); $heal = ($health+1); if ($_POST['amount']){ $amount = ($_POST['amount']); $healing = ($heal*$amount); $cashloss = ($purchase*$amount); mysql_query("UPDATE users WHERE health='$healing', cash='$cashloss'");} ?> Quote Link to comment https://forums.phpfreaks.com/topic/180314-coding-question/#findComment-951965 Share on other sites More sharing options...
kickstart Posted November 5, 2009 Share Posted November 5, 2009 Hi That update statement isn't updating anything, merely finding the row(s) to update (with a syntax error). You would want something like:- UPDATE users SET health='$healing', cash='$cashloss' WHERE username='$username' However you do not appear to be doing anything with the records you have selected at the start of that code fragment. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/180314-coding-question/#findComment-952024 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.