Multi dimensional array and CSV

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Zeepblok
Forum Newbie
Posts: 3
Joined: Wed May 12, 2010 4:21 am

Multi dimensional array and CSV

Post 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 ?
Zeepblok
Forum Newbie
Posts: 3
Joined: Wed May 12, 2010 4:21 am

Re: Multi dimensional array and CSV

Post by Zeepblok »

Someone got an idea ?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Multi dimensional array and CSV

Post by requinix »

$data[$rowcount][0] is an array...

You want

Code: Select all

$data[$rowcount] = fgetcsv ($fp, 2000, ",");
Zeepblok
Forum Newbie
Posts: 3
Joined: Wed May 12, 2010 4:21 am

Re: Multi dimensional array and CSV

Post by Zeepblok »

Won't I have the same than ? won't [$rowcount] be filled with the entire CVS instead of 1 row ?
Post Reply