Multidimensional Array Storage Problems

Source: Internet
Author: User
Print_r ($dbinsert) display content:


Array
(
[0] = = Array
(
[Apmac] = 0q:4e:cb:00:01:09
[PUB_IP] = 11.24.24.7
[PRIV_IP] = 12.18.1.3
[Hwver] = VA500
[Fwver] = 69.0.0
[VSMIP] = 12.25.1.19
[Conntime] = 677822
[Boottime] = 49950
[state] = =
[Statetime] = 2013-7-12 18:34:5
[hostname] = name1
[Location] = 0004.003.01
[admin_id] = 0
)

[1] = = Array
(
[Apmac] = 10:qe:cv:02:00:37
[PUB_IP] = 11.24.24.7
[PRIV_IP] = 12.18.1.3
[Hwver] = VA500
[Fwver] = 69.0.0
[VSMIP] = 12.25.1.19
[Conntime] = 169547
[Boottime] = 403315
[state] = =
[Statetime] = 2013-7-12 18:34:5
[hostname] = nam2
[Location] = 0004.003.01
[admin_id] = 0
)

[2] = = Array
(
[Apmac] = r0:ve:cb:00:ff:04
[PUB_IP] = 13.24.28.7
[PRIV_IP] = 92.18.1.18
[Hwver] = V
[Fwver] = 6.)
[VSMIP] = 12.25.1.79
[Conntime] = 168
[Boottime] = 144497
[state] = =
[Statetime] = 2013-7-12 18:34:5
[hostname] = Name5
[Location] = 0004.003.01
[admin_id] = 0
)

)



Problem:

I'm going to insert these into the database table Table3, the table structure is the same as the returned content, and the order is the same

How do I write a PHP program?


Reply to discussion (solution)

$f = "; $v = Array () foreach ($dbinsert as $row) {  if (empty ($f)) $f = Join (', ', $array _key ($row));  $v [] = "('". Join ("', '", $row). "')";} $sql = "INSERT INTO Table3 ($f) values". Join (', ', $v);//Execute $SQL statement

$f = "; $v = Array () foreach ($dbinsert as $row) {  if (empty ($f)) $f = Join (', ', $array _key ($row));  $v [] = "('". Join ("', '", $row). "')";} $sql = "INSERT INTO Table3 ($f) values". Join (', ', $v);//Execute $SQL statement



I'm sorry I can't read .... Can you write in a popular point, without considering efficiency and profile?

1. Iterate through the two-dimensional array, merging the elements inside the array into strings (used in the middle, numbers) to form a inset string
Does this not understand?

2. Combine the above strings and SQL statements into inset statements, and add them to the loop.

Version is bull b, worship a bit, I just translate

notice:undefined Variable:array_key in dex3.php on line Fatal error:function name must bes a string in dex3.php on Li NE 19


if (empty ($f)) $f = Join (', ', $array _key ($row));

if (empty ($f)) $f = Join (', ', Array_keys ($row));

1. Iterate through the two-dimensional array, merging the elements inside the array into strings (used in the middle, numbers) to form a inset string
Does this not understand?

2. Combine the above strings and SQL statements into inset statements, and add them to the loop.

Version is bull b, worship a bit, I just translate

Three elder brother, smart

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.