Monk3h Posted January 14, 2009 Share Posted January 14, 2009 I am trying to create a way to buy units on my game, i have created an array to bring the units info from the database and displayed it in a table. My problem is when it comes to actually buying some units. I have a text box appearing next to each unit which will be used by a player to enter the amount of each unit they wish to buy. How would i define the text boxes to each unit in the array so that when they hit BUY the right amount of each unit is purchased. Thanks in Advance, Monk3h. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 14, 2009 Share Posted January 14, 2009 <input type="text" name="buy[1]" value="0" /> <input type="text" name="buy[2]" value="0" /> <input type="text" name="buy[3]" value="0" /> <input type="text" name="buy[4]" value="0" /> where 1,2,3,4 are the IDs for each item. when that is posted, you can loop over the values like: foreach($_POST['buy'] as $id=>$num){ if(!is_numeric($num) || $num < 1) continue; echo "You want $num of $id"; } Quote Link to comment 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.