Subtract number from Mysql using a button

  RicScott 23:30 06 Jan 2007

Hi all..
Just a quickie..

I've designed an Intranet site, one of the tables is for spare parts. The issue I have is, the client now wants a button under the stock availability number to subtract (-1) from the stock table whenever a part is used.
The site is built with php using a MySQL Db.

Basically what I want it to do is, for example:

3 in Stock

Press the button, the display should now show..

2 in Stock
And so on...
Any ideas anyone? I'm stuck on this one...

The field type is set to INT but can be altered easily to another type if needed.

  LeadingMNMs 09:43 07 Jan 2007

I'm not sure if there is a simpler way, but I would do it as,

Query database to find current stock (I guess your displaying this and other data about the part)

Make sure you keep the key to the row. If you don't want it to be displayed put it in a hidden input field.

When the user clicks the button, re-query the database (they may have been sitting there for an hour on the screen while another user has used a part already) and get the current stock.

Reduce the local stock variable by 1 "$stock -= 1"

Update the database with the new value, "UPDATE partsTable SET stock = '$stock' WHERE tableKey = '$key'".

  RicScott 11:19 11 Jan 2007

Thanks for that..Sorry for the delay..

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

Galaxy Note 8 vs iPhone X

Awful clip art from 1994 is being tweeted every hour by a bot

iPhone X vs Samsung Galaxy Note 8

Les meilleurs navigateurs internet 2017