I will make this as short and descriptive as possible (considering my case is way longer).
Lets say I have 2 database tables with the following structures:
User table:
id —- username—- gold
Items table:
id—– item_name—- item_price
What I am trying to achieve is brainstorming, I tried this with over 20 script combinations. I need to be able to echo out all items in the table to a good layout (done)
Have a text box for the user to type in the value required to be bought.
an a href to submit the amount, deduct the price of the item from the amount of gold the user has, then add 1 to the inventory. I am not requiring php code, as it is easy. All I need is help with trying to update the value typed in “Live”. The layout of the “shop” will look something like this:
while($_row = mysql_fetch_assoc($query)){
echo out name...
<input type = 'text' name = 'to_buy_value'/>
<a href = 'javascript:;' class = 'buy'>Buy</a>
}
I hope the above code gives you enough reference.
TL;DR (after db structure?)
1- A text box with an a href as the submit.
2- table update is done on-the-fly (no reloads). Ajax.
3- Be able to buy more than 1 item at a time without page reloads
4-no help with php code required unless necessary.
I’d appreciate any sort of help.
Here’s a very rough solution for you. In your while loop you could attach the item’s database id to the id of the element:
Then bind a javascript function to your “Buy” link which will make an AJAX request:
The “purchaseItem.php” file could return a simple JSON object that holds the player’s current gold and item amount for the inventory. Or you could return HTML, depending on how your page is setup.