0

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 Answers1

0

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++;
                };
            };
syroz
  • 49
  • 5
  • why semicolon after while and for loop ? – Sachink Mar 28 '15 at 11:35
  • the table get updated. actually i count inserted data as well. And now i think that problem is in the way i try to output `$up` – Nevis Franko Mar 28 '15 at 11:41
  • something is wrong in your code which is not visible to us, you are showing limited code, otherwise your input not meeting the conditions which is required to execute $up++; – Sachink Mar 28 '15 at 11:52