Jump to content

create array for each row from csv file troubles...


Recommended Posts

I've been trying to get this to work without success and I'm banging my head on the wall...  I'm still new to php and I'm not sure what I'm missing or where I'm going wrong.

 

I have a csv file that I want uploaded.  <- This I can achieve

I want the csv file to be read from the second row (discarding the headers)

For each row in the csv I want an array created and printed...

 

I have pieced together this bit of code but it's not working so well...  It uploads fine but it will only read and create an array for the first row- the row of headers that I want to ignore... 

 

I've read about array shift and file() and all sorts of other stuff but now my head's swimming... I would much appreciate some guidance or at least some suggestions as to where to start to write this code successfully...

 

Thanks in advance.

 

-Julian

 

<?php
$target = "files/";
$target = $target . basename( $_FILES['results']['name']) ;

  	move_uploaded_file($_FILES['results']['tmp_name'], $target);

$csvfile = $target;

$handle = fopen($csvfile, "r");

while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
	$num = count($data); 
	$row++;
	for ($c=0; $c < $num; $c++) {
	}

	$pubData = array (
		'core_author' => 'Admin',//username
		'core_creatorID' => 2,//userid
		'core_creator' => 'Admin',//username
		'core_approvalState' => 'approved',//id of state, according to your workflow
		'core_topic' => -1,//topic id, -1 for all topic
		'core_showInList' => 1,
		'core_showInMenu' => 1,
		'core_online' => 1,
		'core_revision' => 0,
		'core_language' => 'x_all',//lang code or 'x_all' for all languages
		'core_publishDate' => '2006-09-06 17:26:29',//publish date if shown format, use eg strftime("%Y-%m-%d %H:%M:%S", time()
		'core_expireDate' => '',//date format the same as above
		'organization' => $data[0],//all the USCF fields here!
		'year' => $data[1],
		'eventPermit' => $data[2],
		'raceDate' => $data[3],
		'discipline' => $data[4],
		'category' => $data[5],
		'gender' => $data[6],
		'class' => $data[7],
		'age' => $data[8],
		'license' => $data[9],
		'lastName' => $data[10],
		'firstName' => $data[11],
		'bib' => $data[12],
		'teamName' => $data[13],
		'time' => $data[14],
		'place' => $data[15]);

}
fclose($handle);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.