php - multi row validation -


i'm making barcode system, validation depends in 1 row supposed validate depends on request qty of item. works in 1 item when add item. validate on wrong way. ex: request qty 10. when item reaches 10. can't add item because depends in 1 row.

barcode image

i have 3 tables inner join.

| stockrequesttb     |  ---------------------- |in_code |requestqty | |        |           |         | receivetb                     | --------------------------------- |itemcode|  status   |refnumber | |        |           |          |   | allinvty3          | ---------------------- |in_code |  item     | |        |           | 

here's code:

<form method ="post">  <input type="text" name="itemcode">   </form>  <?  if(isset($_post['itemcode']))     {         $sql="select allinvty3.*, receivetb.* ,  stockrequesttb.*, count(receivetb.itemcode) icount  receivetb    inner join stockrequesttb on receivetb.itemcode =stockrequesttb.in_code        inner join allinvty3 on receivetb.itemcode = allinvty3.in_code     receivetb.refnumber='$temp'  group  receivetb.itemcode";      $result = $conn->query($sql);    while($row = $result->fetch_assoc()) {     $icount = $row['icount'];     $qty = $row['requestqty'];     $total1 =$row['itemcode'];  }  if($itemcode!== $total1)     {         echo"<script type=\"text/javascript\">alert('no item found'); </script>";     } ?> 

this problem. made sql count icount make sure items equal in request. wrong here depend on 1 row , can't add item if request qty equal.

<?  if($icount == $row['requestqty'])      {          echo"<script type=\"text/javascript\">alert('over'); </script>";     }     else {     /*my insert code works here*/     }     } ?> 

try code

select     receivetb.itemcode,     allinvty3.item,     receivetb.refnumber,     stockrequesttb.requestqty,     count(receivetb.itemcode) icount receivetb     inner join stockrequesttb on receivetb.itemcode = stockrequesttb.in_code     inner join allinvty3 on receivetb.itemcode = allinvty3.in_code receivetb.refnumber = '$temp' group     receivetb.itemcode, allinvty3.item,     receivetb.refnumber,     stockrequesttb.requestqty 

and change line:

if($icount == $row['requestqty']) 

to be:

if($icount >= $qty) 

also have change if($itemcode!== $total1) if(!$total1)