how to do loop for array which have different data for each array
Posted
by
Suriani Salleh
on Programmers
See other posts from Programmers
or by Suriani Salleh
Published on 2013-06-27T03:45:47Z
Indexed on
2013/06/27
4:30 UTC
Read the original article
Hit count: 379
i have this file XML file.. I need to convert it form XMl to MYSQL. if it have only one array than i know how to do it.. now my question how to extract this two array
Each array will have different value of data..for example for first array, pmIntervalTxEthMaxUtilization data : 0,74,0,0,48 and
for second array pmIntervalRxPowerLevel data: -79,-68,-52 , pmIntervalTxPowerLevel data: 13,11,-55
. can some one help to guide how write php code to extract this xml file to MY SQL
<mi>
<mts>20130618020000</mts>
<gp>900</gp>
<mt>pmIntervalRxUndersizedFrames</mt> [ this is first array]
<mt>pmIntervalRxUnicastFrames</mt>
<mt>pmIntervalTxUnicastFrames</mt>
<mt>pmIntervalRxEthMaxUtilization</mt>
<mt>pmIntervalTxEthMaxUtilization</mt>
<mv>
<moid>port:1:3:23-24</moid>
<sf>FALSE</sf>
<r>0</r> [the data for 1st array i want to insert in DB]
<r>0</r>
<r>0</r>
<r>5</r>
<r>0</r>
</mv>
</mi>
<mi>
<mts>20130618020000</mts>
<gp>900</gp>
<mt>pmIntervalRxSES</mt> [this is second array]
<mt>pmIntervalRxPowerLevel</mt>
<mt>pmIntervalTxPowerLevel</mt>
<mv>
<moid>client:1:3:23-24</moid>
<sf>FALSE</sf>
<r>0</r> [the data for 2nd array i want to insert in DB]
<r>-79</r>
<r>13</r>
</mv>
</mi>
this is the code for one array that i write..i dont know how to write code for two array because the field appear two times and have different data value for each array
// Loop through the specified xpath
foreach($xml->mi->mv as $subchild)
{
$port_no = $subchild->moid;
$rx_ses = $subchild->r[0];
$rx_es = $subchild->r[1];
$tx_power = $subchild->r[10];
// dump into database;
...........................
i have do a little research on it this is the out come...
$i = 0;
while( $i < 5)
{
// Loop through the specified xpath
foreach($xml->md->mi->mv as $subchild)
{
$port_no = $subchild->moid;
$rx_uni = $subchild->r[10];
$tx_uni = $subchild->r[11];
$rx_eth = $subchild->r[16];
$tx_eth = $subchild->r[17];
// dump into database;
..............................
$i++;
if( $i == 5 )break;
}
}
// Loop through the specified xpath
foreach($xml->mi->mv as $subchild)
{
$port_no = $subchild->moid;
$rx_ses = $subchild->r[0];
$rx_es = $subchild->r[1];
$tx_power = $subchild->r[10];
// dump into database;
.......................
© Programmers or respective owner