I am very new to mysql and php. I need to put an array from php into a data table:
The array looks like this:
$memberdata
Key value
apple 5
banana 8
salmon 3
candle 4
..........
and 100 more...
My mysql table looks like this:
MemberTable
ID(INT11)=PK MemID(INT11) stuff(varchar) value(INT2)
1 23 apple 5
2 23 banana 8
3 23 salmon 3
4 23 candle 4
5 45 banana 1
6 45 apple 9
So each member; here member 23 and 45 can have the same stuff but with other values, so for every member i have one php array of data. (mysql ID is auto increment).
My question: is there a possibility to store an array directly into a mysql table...? In a book that i read they make a foreach loop and in the loop they open a connection to the database... so i thought that is maybe to time consuming:
book example:
$cxn = mysqli_connect($host,$user,$pass,$dbname);
$MemID = "23";
$query_pre = "INSERT INTO MemberTable ('MemID','stuff','value') VALUES (";
Foreach ($memberdata as $stuff => $value)
{
$query = $query_pre . "$MemID,$stuff,$value)";
$result = mysqli_query($cxn, $query) or die ("Couldn't execute query");
}
Regards, Thijs