我正在尝试将此代码从 Java 复制到 php 中,但我无法完全弄清楚如何获取行/列的内容?
这是java代码:
ResultSet resultsRS = statement.executeQuery("select distinct snum from shipments where quantity >= 100");
int rowCount=0;
while(resultsRS.next()){
statement2.executeUpdate("UPDATE suppliers SET status = status + 5 WHERE snum = "+"\""+resultsRS.getString(1)+"\"");
rowCount++;
}
到目前为止,我在 php 中有这个:
$result2 = mysqli_query($database,"select distinct snum from shipments where quantity >= 100");
$rowCount = 0;
foreach($result2 as $shipment){
mysqli_query($database,"UPDATE suppliers SET status = status + 5 WHERE snum = "."\"".$shipment."\"");
rowCount++;
}
但是,这并没有按预期工作。
另外,如果您注意到我想要的只是要更新一个特定的列。
编辑:让它工作
对于阅读的每个人,我都可以通过以下代码得到我想要的东西:
for($counter=0; $row = mysqli_fetch_row($result2);$counter++){
foreach($row as $key=> $value){
mysqli_query($database,"UPDATE suppliers SET status = status + 5 WHERE snum = "."\"".$value."\"");
$rowCount++;
}
}