dtmwnqng38644 2015-03-28 11:07
浏览 84

变量循环不会增加

Need to count updated data in the table, but $up stays 0. Data received from imported csv file.

$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,",","'"));

there's code below do-while loop where I choose the file and get the messege about $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> 
...
  • 写回答

1条回答 默认 最新

  • douju4594 2015-03-28 11:30
    关注

    From what i can see, i'm pretty sure that you are inserting and not updating.

    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)

    You should verify what you are doing in the while(condition)

                  for($i = 0; $array[$i] = mysql_fetch_assoc($res); $i++){
    
                    while ((condition)){
                            $check = true;
                            $i++;
                    };
                };
    
    评论

报告相同问题?

悬赏问题

  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数