This was working properly but now I’m having some issues that I’d like to clear up.
[ul][li]I need php to skip header line[/li]
[li]The CSV is only being read for one line, not multiple lines[/li][/ul]
The array seems to have no issues, but If I upload a CSV with a header, it only inserts the header row in the db, and if no header is there it only reads the first line in. I tried a while loop (feof $handle) but it just kept going and froze up the browser on a 6 line CSV. Here is my CSV reading code:
[php]if(isset($_POST[‘submit’]))
{
$file = $_FILES[“file”][“tmp_name”];
$handle = fopen($file, “r”);
$filesop = fgetcsv($handle, 0, “,”);
$coldata = array();
$coldata[ “orderNumber” ] = $filesop[0];
$coldata[ “place” ] = $filesop[1];
//This goes on for 200 array elements, and then I define a table array and my main loop:
$tablenames = array(“staging”);
for($tableno = 0;$tableno < sizeof($tablenames);$tableno++){
$q = “”;
$q2 = “”;
$q3 = “”;
$q4 = “”;
$q5 = “”;
$q6 = “”;
$col_list = ‘'.str_replace(',','
,',$table_cols[$tableno]).'
’;
$q .= “INSERT INTO “.$tablenames[$tableno].” (”.$col_list.") VALUES (";
$last_id = mysqli_insert_id($connect);
$cols = explode(",",$table_cols[$tableno]);
$data = array();
foreach($cols as $key => $fldname) {
$data[] = “’”.$coldata[$fldname]."’";
}
/*INSERT INTO STAGING TABLE - INITAL CSV UPLOAD*/
$q .= implode(",",$data).");";[/php]
Any help to make sure this avoids the header and reads all lines in is greatly appreciated