douyangqian5243 2015-04-16 17:39
浏览 41

如何在Joomla 3.0或PHP中将多维数组保存到数据库

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.

  • 写回答

1条回答 默认 最新

  • dongmi4720 2015-04-16 17:48
    关注

    If you know how to store it in MySQL by using pure php then simplest way to use some extension like a 'JUMI' which lets you to use php in joomla, without using the joomla classes. here is the link to joomi extension: http://extensions.joomla.org/extensions/extension/core-enhancements/coding-a-scripts-integration/jumi

    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)