我正在制作条形码系统,我的验证只取决于应该验证的一行取决于我的项目的请求数量。它在一个项目中工作,但当我添加另一个项目。它只会以错误的方式验证。例如:当项目达到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*/
}
}
?>
答案 0 :(得分:1)
试试此代码
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)