Insert Multidimensional array into Mysql Database

Hi Guys,

My head is melted… I need to insert a multidimensional array into mysql database. This is what I have could you please have a look and tell me where I’m going wrong.

Array:

$arrayData = array(
	 array(
		'id' => 1,
		'firstName' => 'Paul',
		'surname' => 'Crowe',
		'age' => 28,
		'gender' => 'male',
		'connections' => array(2),
		'cities' => array('Dublin' => 80, 'New York' => 100, 'Paris' => 95, 'Madrid' => 100, 'London' => 80, 'Barcelona' => 100, 'Moscow' => 20)
	),
	 array(
		'id' => 2,
		'firstName' => 'Rob',
		'surname' => 'Fitz',
		'age' => 23,
		'gender' => 'male',
		'connections' => array(1, 3),
		'cities' => array('Dublin' => 40, 'New York' => 100, 'Paris' => 65, 'Madrid' => 90)
	),
	 array(
		'id' => 3,
		'firstName' => 'Ben',
		'surname' => "O'Carolan",
		'age' => null,
		'gender' => 'male',
		'connections' => array(2, 4, 5, 7),
		'cities' => array('Paris' => 90, 'Madrid' => 40, 'London' => 85, 'Barcelona' => 90, 'Moscow' => 80)
	),
	 array(
		'id' => 4,
		'firstName' => 'Victor',
		'surname' => '',
		'age' => 28,
		'gender' => 'male',
		'connections' => array(3),
		'cities' => array('Paris' => 80, 'Madrid' => 80, 'London' => 80, 'Barcelona' => 80, 'Moscow' => 40)
	),
	 array(
		'id' => 5,
		'firstName' => 'Peter',
		'surname' => 'Mac',
		'age' => 29,
		'gender' => 'male',
		'connections' => array(3, 6, 11, 10, 7),
		'cities' => array('Dublin' => 60, 'New York' => 100, 'Paris' => 75)
	),
)

foreach($arrayData as $data){

	$sql = "INSERT INTO people (firstName, surname, age, gender, connections, cities)
	VALUES ($data[firstName], $datas[surname], $data[age], $data[gender], $data[connections], $data[cities])";

}






What’s the structure of the tables that you’re going to insert the data into?

id, firstName, surname, age, gender, connections,cities

There are 2 more tables in the database. Cities and connections.

i don’t do php or whatever that was in post #1, but i can see you’re trying to store a string of numbers in a single column called connections, and a string of strings in a column called cities

that’s gonna give you some heartaches – do a search for first normal form