Jump to content

Edgyballz

New Members
  • Posts

    1
  • Joined

  • Last visited

Edgyballz's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi everyone, I am facing a problem with the following code snippet which invovles inserting data from a csv file into a mysql table. <?php if(isset($_POST['submit'])) { $file = $_POST['filepath']; $handle = fopen($file,"r"); $fileop = fgetcsv($handle,2000,","); //read only headers (first row) // build qry to select data from assessment,assessmenttype tables $qry = "SELECT assessmenttype.AssessType_Code, Assess_Num FROM assessment, assessmenttype WHERE assessmenttype.AssessType_Code = assessment.AssessType_Code AND Offer_ID = '$offerId';"; // execute query $result = mysql_query($qry) or die('Query failed: ' . mysql_error()); $c = 1; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $index = $_POST["lstAssess$c"]; $assessNum = $row['Assess_Num']; $assessCode = $row['AssessType_Code']; echo $assessCode." ".$assessNum." ".$fileop[$index]; $i = 1; while((${"fileop$i"} = fgetcsv($handle,10000,",")) !== false) { echo ${"fileop$i"}[$index]; /* $Stud_Lname = $fileop[0]; $Stud_Fname = $fileop[1]; $Stud_Id = $fileop[2]; $mark = $fileop[$index]; $qry = mysql_query("INSERT INTO gradebook (Stud_ID,Offer_ID,Assess_Num,AssessType_Code,GB_Mark) VALUES ('$Stud_Id','$offerId','$assessNum','$assessCode','$mark')")or die('Query failed: ' . mysql_error());*/ echo "<br>"; $i = $i + 1; } //echo $fileop[$index]; $c = $c + 1; } }else { echo "Error!"; } //close database connection mysql_close($conn); ?> As expected, each outer loop run should generate every inner loop run. This is not the case here. Only the first loop is successful and gets inserted into the DB. Can anyone point me to directions where I can tackle this issue?? Thanks in advance.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.