I have a multidimensional array which can be varying in length from 1 to 40+ arrays within an array that I need to add to a database table in Joomla 3. Here is a sample one with 4 arrays:
Array
(
[0] => Array
(
[0] => Array
(
[0] => 5
[1] => cbb807
[2] => 8
[3] => 8
[4] => Polycorp3-1
[5] => Polycorp3
[6] => 18
[7] => 339.00000
[8] => 339.00000
[9] => 339.00000
[10] => 82
[11] => 2250
[12] => Phone
[13] => Polycorpm
[14] => Jones
)
)
[1] => Array
(
[0] => Array
(
[0] => 5
[1] => cbb807
[2] => 8
[3] => 8
[4] => Polycorp3-1
[5] => Polycorp3
[6] => 18
[7] => 339.00000
[8] => 339.00000
[9] => 339.00000
[10] => 82
[11] => 2250
[12] => Phone
[13] => Polycorpm
[14] => Jones
)
)
[2] => Array
(
[0] => Array
(
[0] => 5
[1] => cbb807
[2] => 8
[3] => 8
[4] => Polycorp3-1
[5] => Polycorp3
[6] => 18
[7] => 339.00000
[8] => 339.00000
[9] => 339.00000
[10] => 82
[11] => 2250
[12] => Phone
[13] => Polycorpm
[14] => Jones
)
)
[3] => Array
(
[0] => Array
(
[0] => 5
[1] => cbb807
[2] => 8
[3] => 8
[4] => Polycorp3-1
[5] => Polycorp3
[6] => 18
[7] => 339.00000
[8] => 339.00000
[9] => 339.00000
[10] => 82
[11] => 2250
[12] => Phone
[13] => Polycorpm
[14] => Jones
)
)
The code I have doing this is:
$dbo = JFactory::getDbo();
$query = $dbo->getQuery(true);
$columns = array( 'ordering', 'state', 'checked_out', 'created_by', 'devicetype', 'manufacturer', 'model', 'serialnumber', 'market', 'cost', 'date_purchased', 'partner', 'current_customer', 'current_location', 'original_customer', 'date_recieved', 'date_recently_deployed', 'notes', 'ordernumber', 'status', 'ist', 'arp', 'walken', 'cheese', 'pt_id', 'budgeted_cost', 'firmware', 'other_ist', 'sell_price', 'current_term');
$values = array();
foreach ($data as $key => $array) {
$values = array(1,1,0,82,$db->quote($data['12']),$db->quote($data['13']),$db->quote($data['5']),$db->quote($Serial_Number),$db->quote($Market),$db->quote($data['7']),$db->quote($Date_Purchased),$db->quote($data['14']),$db->quote($data['11']),$db->quote($Current_Location),$db->quote($Previous_Customer),$db->quote($Date_Recieved),$db->quote($Date_Time_was_deployed_currently),$db->quote($Notes),$db->quote($Order_Number),$db->quote($Status),$db->quote($aa),$db->quote($bb),$db->quote($cc),$db->quote($dd),$db->quote($deviceId),$db->quote($Budgeted_Costs),$db->quote($Firmware),$db->quote($ee),$db->quote($Sell_Price),$db->quote($Current_Term_in_Months));
}
$query->insert($dbo->quoteName('#__inventory_einventoryitems'));
$query->columns($columns);
$query->values($values);
$dbo->setQuery($query);
$dbo->execute();
The problem I am running into is that it runs, but it seems to be returning ARRAY() and nothing is saved to the database. It seems like it should work. I know I have a mistake, I just can not see where.
I would prefer to use joomla classes, but if someone has a better solution in php/mysql. I am open to that as well.