php - Set maximum input number -
my question quite complex. working on loan system. have 2 tables regarding loan module:
- item
- loan
when item being loaned, loaned quantity subtracted inventory(item_qty - loan_qty). problem comes @ update loan module. don't know how set maximum quantity. know need add item_qty , loan_qty, can't find way so.
i've googled long time , still stuck. here code:
<?php $loan_id=$_get['loan_id']; $acc_query = $con->query("select * `loan` natural join `item` loan_id = '$_request[loan_id]' ") or die(mysqli_error()); $acc_fetch = $acc_query->fetch_array(); ?> <div> <form method="post" action="update_loan.php" > <input type="hidden" name="item_id" value="<?php echo $item_id; ?>"> <input type="hidden" name="loan_id" value="<?php echo $loan_id; ?>"> <div class = "form-group"> <label>quantity</label> <input name="n_qty" type = "number" id = "n_qty" value= "<?php echo $acc_fetch['qty']?>" class = "form-control" min="1" max="??" /> </div> </div>
table inventory:
- item_id
- item_code
- item_name
- item_qty
table loan:
- loan_id
- item_id
- loan_qty
- loaned_place
can use group item_id, item_code, item_name
, use sum()
function sum of qty both tables: inventory
, loan
, , subtract desired one.
select i.item_id,i.item_code,i.item_name, (sum(i.item_qty) - sum(l.loan_qty)) resultqty `inventory` natural join `loan` l group i.item_id,i.item_code,i.item_name
Comments
Post a Comment