I have a web form that allows users to enter in a quantity of an item that they would like to "collect" for a game.
When they click the "Submit" button, a php file is called to process the items and the quantities. The file queries a database table that stores the links that users follow to "collect" the items.
The link table is setup similar to
link_d | timestamp | item_id | link
What I'm wanting to do is check the number of available links in the table against what the user requested and see if there are enough links for the request. If there are not, then I want to change the quantity requested to the number of available links. I'm wondering what would be the best way to go about that.
Right now I'm thinking about something like
for($counter=0;$counter<count($items_name);$counter++)
{
if($items_qty > $qtyavail = "select count(links.link) from links inner join items on links.item_id = items.item_id where items.name = '".$items_name[$counter]."' ;")
{
$items_qty = $qtyavail
}
}
As the number of available links will change over time, I'm needing the current number available in the table when the user clicks the Submit button.
Any thoughts/suggestions?
Limit $requestsmaybe