我正在制作条形码系统,我的验证仅依赖于应该验证的一行,该行取决于我项目的请求数量。它在一个项目中有效,但是当我添加另一个项目时。它只会以错误的方式进行验证。例如:请求数量仅为10。当项目达到10时,我无法添加其他项目,因为它仅取决于一行。
我有3个表可以进行内部联接。
| stockrequesttb |
----------------------
|in_code |requestqty |
| | |
| receivetb |
---------------------------------
|itemcode| status |refnumber |
| | | |
| allinvty3 |
----------------------
|in_code | item |
| | |
这是我的代码:
<form method ="POST">
<input type="text" name="itemcode">
</form>
<?
if(isset($_POST['itemcode']))
{
$sql="SELECT allinvty3.*, receivetb.* , stockrequesttb.*, count(receivetb.itemcode) as icount from receivetb
INNER JOIN stockrequesttb on receivetb.itemcode =stockrequesttb.in_code
INNER JOIN allinvty3 on receivetb.itemcode = allinvty3.in_code
where receivetb.refnumber='$temp' group by 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>";
}
?>
这是我的问题。我做了一个SQL计数,这是icount,以确保项目在请求中是相等的。这里有什么问题,它仅取决于一行,并且如果请求数量已经相等,则我无法添加另一项。
<?
if($icount == $row['requestqty'])
{
echo"<script type=\"text/javascript\">alert('Over'); </script>";
}
else {
/*My INSERT CODE works here*/
}
}
?>
试试这个代码
SELECT
receivetb.itemcode,
allinvty3.item,
receivetb.refnumber,
stockrequesttb.requestqty,
COUNT(receivetb.itemcode) AS icount
FROM receivetb
INNER JOIN stockrequesttb ON receivetb.itemcode = stockrequesttb.in_code
INNER JOIN allinvty3 ON receivetb.itemcode = allinvty3.in_code
WHERE receivetb.refnumber = '$temp'
GROUP BY
receivetb.itemcode, allinvty3.item,
receivetb.refnumber,
stockrequesttb.requestqty
并更改此行:
if($icount == $row['requestqty'])
成为:
if($icount >= $qty)
另外,您必须将其更改if($itemcode!== $total1)
为if(!$total1)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句