Jump to content

Noob question


Monk3h

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/140855-noob-question/
Share on other sites

<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";
}

Link to comment
https://forums.phpfreaks.com/topic/140855-noob-question/#findComment-737259
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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