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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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