0

Pls help me..Any given idea is welcome.

Am been working on this project. I created a table called drugs & created another table called orders... Now i have like quantity as a column in my drugs table.. In orders table how can someone makes an order of a drug so it should subtract it from the qauntity column of the drug table... E.g Drugs table.... Has a column named quantity... We have quantity as 5... The how can one makes 1 order so it should subtract it from 5 to remainder 4 to be left in quantity... Pls any observation thanks for listening.

27th Feb 2020, 4:39 AM
Nwankwo Valentine
Nwankwo Valentine - avatar
5 odpowiedzi
+ 1
the only way to decrease quantity is to update: $result = $conn->query("select quantity from drugs where columnname = columnvalue "); if($row = $result->fetch_assoc()){ $newqty = $row['quantity'] - 1; $query = "update drugs set quantity = $newqty where columnname = columnvalue "; if( $conn->query($query)){ echo "updated"; }else{ echo "fail to updated"; } }
27th Feb 2020, 10:09 AM
Soo Zhan Nam
Soo Zhan Nam - avatar
+ 2
What are you using this in? php or js?
27th Feb 2020, 5:47 AM
coddy
coddy - avatar
0
27th Feb 2020, 6:42 AM
Nwankwo Valentine
Nwankwo Valentine - avatar
0
Well then, you can simply run a query to the table called drugs, using mysqli_query() and then run a query to deduct the quantity of drugs from the current stock. EDIT: Also, what use is the drugs table? Do you have multiple rows with different types of drugs in them?
27th Feb 2020, 8:02 AM
coddy
coddy - avatar
0
Soo Zhan Nam Thank you
27th Mar 2020, 6:57 PM
Nwankwo Valentine
Nwankwo Valentine - avatar