[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

php mysql stock deduction

Posted on 2010-01-01
3
Medium Priority
?
774 Views
Last Modified: 2012-05-08
when user order  a pro duct I prepaire the order like the picture below  but how can i deduct the product from ' product ' table
if some item order more than I have on stock i must let user correct the quantity that they want until it fit my stock that i have

Please suggest php or sqlstate ment
CREATE TABLE IF NOT EXISTS `product` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `ProductId` varchar(80) DEFAULT NULL,
  `ProductName` varchar(255) DEFAULT NULL,
  `ProductType` varchar(255) DEFAULT NULL,
  `ProductPrice` varchar(255) DEFAULT NULL,
  `ProductQuantity` varchar(255) DEFAULT NULL,
  `DateTime` datetime DEFAULT NULL,
  `TimeStamp` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `ProductId` (`ProductId`),
  KEY `ProductId_2` (`ProductId`),
  KEY `ProductName` (`ProductName`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ;

Open in new window

new.JPG
0
Comment
Question by:teera
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
igni7e earned 1000 total points
ID: 26157650
This is kinda an ugly way, but it's quick:

SQL:
$QUERY = "SELECT QUANTITY-" . $SELECTED_AMOUNT . " AS REMAINING_AMOUNT FROM PRODUCT WHERE PRODUCTCODE = " . $PROD_CODE

PHP:
$PROD_CODE will be the product the user selected
$SELECTED_AMOUNT will be the quantity the user selected
The sql result will be the remaining quantity you have for sale

0
 
LVL 83

Assisted Solution

by:leakim971
leakim971 earned 1000 total points
ID: 26157679
Hello teera,

You don't want negative number for the stock ?
You may have two column/field for the stock :

current_stock (0 to unlimited)
coming_stock (negative or positive)

Regards.
0
 
LVL 83

Expert Comment

by:leakim971
ID: 26161497
Thanks for the points!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month19 days, 9 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question