cdoyle Posted October 7, 2008 Share Posted October 7, 2008 Hi, This seems like it should be easy, but searching around I haven't been able to figure out how to this yet. I finally got the paypal integration working with my database, and can update tables etc. So now what I'm trying to do is, when a user purchases 'donor pack 1' via a paypal button. I want to update the database and give them a total of 15 of a particular item. So I need to insert into the items table 15 rows of the item for this player. I can get it to add 1 row, but not sure how to make it insert all 15? Here is what I have now. $updateweapon = mysql_query("insert into items(player_id,item_id,status)values('.$option_name1.','10','unequipped')"); Is there a loop or something, where I can hardcode how many rows I wan to insert? Quote Link to comment https://forums.phpfreaks.com/topic/127329-paypal-integration-inserting-multiple-items-to-table/ Share on other sites More sharing options...
Bendude14 Posted October 7, 2008 Share Posted October 7, 2008 for($i=0; $i<=15; $i++) { //your code here } This will run your code 15 times which in theory will update 15 rows... give it a go Quote Link to comment https://forums.phpfreaks.com/topic/127329-paypal-integration-inserting-multiple-items-to-table/#findComment-658667 Share on other sites More sharing options...
R0bb0b Posted October 7, 2008 Share Posted October 7, 2008 15 rows, one for each number in quantity seems a little excessive and a good way to force yourself into archiving data early. Why don't you just add a quantity column? Quote Link to comment https://forums.phpfreaks.com/topic/127329-paypal-integration-inserting-multiple-items-to-table/#findComment-658672 Share on other sites More sharing options...
Bendude14 Posted October 7, 2008 Share Posted October 7, 2008 yes i agree with you R0bb0b the quantity column definitely would be they way to go Quote Link to comment https://forums.phpfreaks.com/topic/127329-paypal-integration-inserting-multiple-items-to-table/#findComment-658839 Share on other sites More sharing options...
cdoyle Posted October 7, 2008 Author Share Posted October 7, 2008 Thank You for responding, and posting how to insert multiple rows. As for the quantity column, this part of the game I didn't develop but maybe I'll give it a try and see how it works. Question tho, I'm work more with Access and one of the things I always see on the Access forums is, that you should never have fields for calculated items. You should get the totals via queries instead. Is MySQL different, and having fields for holding totals of items OK? Thanks! Chris. Quote Link to comment https://forums.phpfreaks.com/topic/127329-paypal-integration-inserting-multiple-items-to-table/#findComment-658910 Share on other sites More sharing options...
R0bb0b Posted October 7, 2008 Share Posted October 7, 2008 Thank You for responding, and posting how to insert multiple rows. As for the quantity column, this part of the game I didn't develop but maybe I'll give it a try and see how it works. Question tho, I'm work more with Access and one of the things I always see on the Access forums is, that you should never have fields for calculated items. You should get the totals via queries instead. Is MySQL different, and having fields for holding totals of items OK? Thanks! Chris. Its all about preserving data, because if you ever need those stats or you realize that you've had an error this whole time or any number of reasons and you calculate them before entering them, you haven't preserved the data to fall back on. That's my view anyway. Quote Link to comment https://forums.phpfreaks.com/topic/127329-paypal-integration-inserting-multiple-items-to-table/#findComment-659039 Share on other sites More sharing options...
cdoyle Posted October 7, 2008 Author Share Posted October 7, 2008 Thank You for responding, and posting how to insert multiple rows. As for the quantity column, this part of the game I didn't develop but maybe I'll give it a try and see how it works. Question tho, I'm work more with Access and one of the things I always see on the Access forums is, that you should never have fields for calculated items. You should get the totals via queries instead. Is MySQL different, and having fields for holding totals of items OK? Thanks! Chris. Its all about preserving data, because if you ever need those stats or you realize that you've had an error this whole time or any number of reasons and you calculate them before entering them, you haven't preserved the data to fall back on. That's my view anyway. OK, I'm going to have to think about how to tackle that. I'm using ezRPG as my base code, and right now when players add items to their inventory it adds a new row to the items table. Then the rows are deleted etc as the player uses the items. I'll have to think about how to do something like this, and still have it work with the game. For the time being, I'm going to try the code that was suggested earlier I'm using this, but it's not working. It's not adding anything now? It was working before I added the new code. Any ideas? if ( $item_number == "1") { for($i=0; $i<=15; $i++) { $updateweapon = mysql_query("insert into items(player_id,item_id,status)values('.$option_name1.','10','unequipped')"); } } [code] Quote Link to comment https://forums.phpfreaks.com/topic/127329-paypal-integration-inserting-multiple-items-to-table/#findComment-659450 Share on other sites More sharing options...
Bendude14 Posted October 8, 2008 Share Posted October 8, 2008 any errors? what happens exactly? just a blank page? Quote Link to comment https://forums.phpfreaks.com/topic/127329-paypal-integration-inserting-multiple-items-to-table/#findComment-659616 Share on other sites More sharing options...
redarrow Posted October 8, 2008 Share Posted October 8, 2008 Look that why your getting problams man ........... You need to get the code to enter a total like 15, your bern that database out lol, bad code pratice there mate................... if you had 100 players at once your using 1500 table rows your game will crash.................. THE CURRENT CODE IS CORRECT CHEEK THAT ==1 THING Quote Link to comment https://forums.phpfreaks.com/topic/127329-paypal-integration-inserting-multiple-items-to-table/#findComment-659634 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.