需要统计表中更新的数据,但 $up 保持为 0。从导入的 csv 文件接收数据。
$up=0;
do { //loop through the csv file
if ($data[0]) {
$res = mysql_query("SELECT ...");
$check=false;
for($i = 0; $array[$i] = mysql_fetch_assoc($res); $i++){
while ((condition)){
$check = true;
$i++;
};
};
if ($check) {
$up++;//this does not work
mysql_query("UPDATE ...");
}
else {
mysql_query("INSERT ...");
}
}
} while ($data = fgetcsv($handle,1000,",","'"));
在 do-while 循环下面有代码,我在其中选择文件并获取有关 $up 的消息
<html>
...
<?php if (!empty($_GET[success])) {echo $up; } ?>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
Choose your file: <br />
<input name="csv" type="file" id="csv" />
<input type="submit" name="Submit" value="Submit" />
</form>
...
最佳答案
据我所知,我很确定您正在插入而不是更新。
your $up is only executed in cas $check is true And your $check is only true if every line in your query meets the (condition)
你应该验证你在 while(condition) 中做了什么
for($i = 0; $array[$i] = mysql_fetch_assoc($res); $i++){
while ((condition)){
$check = true;
$i++;
};
};
关于php - 变量循环不增加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29316397/