Page 1 of 1

Multi dimensional array and CSV

Posted: Wed May 12, 2010 4:26 am
by Zeepblok
Hi,

I used to have the code: the CSV is specified in another php file I can upload it if needed

Code: Select all

$data = fgetcsv ($fp, 2000, ",")

$sql='INSERT INTO test (`name`)
	VALUES (\''.mysql_real_escape_string($data[]).'\')';
		echo $sql."<br>";
		exit();
and it worked 100%

but i needed to make some changes and are using a multi dimensional array now:

Code: Select all

$rowcount = 0;
$data[$rowcount][] = fgetcsv ($fp, 2000, ",")
$sql='INSERT INTO test (`name`)
	VALUES (\''.mysql_real_escape_string($data[$rowcount][0]).'\')';
		echo $sql."<br>";
		exit();
But at the new code the values in $sql are empty and not being filled anymore.

Can someone see what I'm doing wrong ?

Re: Multi dimensional array and CSV

Posted: Sun May 16, 2010 3:51 pm
by Zeepblok
Someone got an idea ?

Re: Multi dimensional array and CSV

Posted: Sun May 16, 2010 4:07 pm
by requinix
$data[$rowcount][0] is an array...

You want

Code: Select all

$data[$rowcount] = fgetcsv ($fp, 2000, ",");

Re: Multi dimensional array and CSV

Posted: Mon May 17, 2010 4:03 am
by Zeepblok
Won't I have the same than ? won't [$rowcount] be filled with the entire CVS instead of 1 row ?