How can I use the foreach loop to get the values for each field (brand_id & brand_name) and have them inserted into the table 'pa_list_brands'?
if I use this code:
$query = db_insert('pa_list_brands')->fields(array('brand_id', 'brand_name'));
foreach ($data as $record) {
$query->values($record);
}
$query->execute();
I get the ERROR: "Catchable fatal error: Argument 1 passed to InsertQuery::values() must be an array, string given"
So I tried this code to see what was being returned with $record:
$query = db_insert('pa_list_brands')->fields(array('brand_id', 'brand_name'));
foreach ($data as $record) {
print_r($record);
}
$query->execute();
And I get ARRAY RESULT:
11Array
(
[0] => stdClass Object
(
[brand_id] => 1
[brand_name] => Gildan
)
[1] => stdClass Object
(
[brand_id] => 2
[brand_name] => American Apparel
)
[2] => stdClass Object
(
[brand_id] => 3
[brand_name] => Rabbit Skins
)
[3] => stdClass Object
(
[brand_id] => 4
[brand_name] => Anvil
)
)
Thank you, Aaron