Jump to content

Search the Community

Showing results for tags 'fgetcsv'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  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.