我是 stackoverflow 的新手。
我正在执行一个选择查询来填充我需要的输出。当它从查询中获取行时,已获取的每一行都是我将它们插入到特定表中。但是,我需要达到的确切行数是 1,767 行,但在执行查询后,输出为 1759。我缺少 8 行。
我的代码有什么问题?
这是我的代码:
$query2 = "SELECT trihadjustmentitems.AdjID AS `adjid1`, trihadjustment.Adj_ID AS `adjid2`,
trihadjustment.AdjToUnitID AS `adjtounitid`, trihadjustment.AdjDate AS `adjdate`, trihadjustmentitems.InvItemsID AS `invitemid`,
trihadjustmentitems.SlsItemsID AS `slsitemid`, trihadjustmentitems.RecipeID AS `recipeid`, trihadjustmentitems.Remark AS `remark`,
trihadjustmentitems.AdjQty AS `adjqty`,
trihadjustment.StockCenter_ID AS `stockcenterid1`, trihadjustmentitems.StockCenter_ID AS `stockcenterid2`
FROM trihadjustmentitems
INNER JOIN trihadjustment ON trihadjustmentitems.AdjID = trihadjustment.Adj_ID";
$result2 = mysqli_query($connection, $query2);
while($row2 = mysqli_fetch_array($result2))
{
$query3 = "INSERT INTO adjustments (adjid1, adjid2, adjtounitid, adjdate, invitemid, slsitemid, recipeid, remark, adjqty, stockcenterid1, stockcenterid2) VALUES ('$row2[adjid1]', '$row2[adjid2]', '$row2[adjtounitid]', '$row2[adjdate]', '$row2[invitemid]', '$row2[slsitemid]', '$row2[recipeid]', '$row2[remark]', '$row2[adjqty]', '$row2[stockcenterid1]', '$row2[stockcenterid2]')";
$result3 = mysqli_query($connection, $query3);
}
最佳答案
没有足够的信息来确定任何地方出了问题。您的代码虽然已过时,但不包含任何可以帮助任何人确定问题所在(如果有任何问题)的内容。我们只能在涉及到数字时信任您,而这不是 IT 的运作方式。
根本不需要您的查询。你可以在没有 while
循环的情况下做你想做的事。只需使用 INSERT INTO ... SELECT
语法。
我会用你的代码来说明
$query = <<<EOF
INSERT INTO adjustments
(adjid1, adjid2, adjtounitid, adjdate, invitemid, slsitemid, recipeid, remark, adjqty, stockcenterid1, stockcenterid2)
SELECT
trihadjustmentitems.AdjID AS `adjid1`,
trihadjustment.Adj_ID AS `adjid2`,
trihadjustment.AdjToUnitID AS `adjtounitid`,
trihadjustment.AdjDate AS `adjdate`,
trihadjustmentitems.InvItemsID AS `invitemid`,
trihadjustmentitems.SlsItemsID AS `slsitemid`,
trihadjustmentitems.RecipeID AS `recipeid`,
trihadjustmentitems.Remark AS `remark`,
trihadjustmentitems.AdjQty AS `adjqty`,
trihadjustment.StockCenter_ID AS `stockcenterid1`,
trihadjustmentitems.StockCenter_ID AS `stockcenterid2`
FROM trihadjustmentitems
INNER JOIN trihadjustment ON trihadjustmentitems.AdjID = trihadjustment.Adj_ID
EOF;
$result = mysqli_query($query);
if(!result) {
echo 'An error occurred';
}
关于php - 在 while 循环上执行选择查询后,并非所有行都插入到表中 - PHP/MYSQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46445725/