Jump to content

SimpleXML insert to database table


Fire2011

Recommended Posts

Hi everyone, wondering if any one could help me, probably simple to most. I am using an API from a video game and I am trying to insert the xml data I get back in to a MYSQL database table. but can't seem to figure it out.

 

I created a simple echo foreach row which works, but I cannot seem to figure it out how to insert in to DB table. also the rows are attributes don't know if that makes a difference?

xml = simplexml_load_file('file.xml');

foreach ($xml->result->rowset->row as $row) {
echo '<tr class="' . $row['ownerName2'] . '">' . '<td>' . $row['date'] . '</td>' . '<td>' . $row['ownerName1'] . '</td>' . '<td>' . $row['ownerName2'] . '</td>' . '<td>' . $row['amount'] . '<b>ISK</b>' . '</td>' . '<td>' . $row['balance'] . '<b>ISK</b></td>' . '<td>' . $row['reason'] . ' </td>' . '</tr>';
};

 

This is the structure of the xml document if you need to have a look.

 

<result>
<rowset name="entries" key="refID" columns="date,refID,refTypeID,ownerName1,ownerID1,ownerName2,ownerID2,argName1,argID1,amount,balance,reason">
<row date="2011-09-16 14:19:00" refID="4873095949" refTypeID="37" ownerName1="name" ownerID1="435353535" ownerName2="name" ownerID2="2342523523" argName1="name" argID1="325235252" amount="-1101525.00" balance="0.00" reason="DESC:"/>
<row date="2011-09-16 14:19:00" refID="4873095949" refTypeID="37" ownerName1="name" ownerID1="435353535" ownerName2="name" ownerID2="2342523523" argName1="name" argID1="325235252" amount="-1101525.00" balance="0.00" reason="DESC:"/>
<row date="2011-09-16 14:19:00" refID="4873095949" refTypeID="37" ownerName1="name" ownerID1="435353535" ownerName2="name" ownerID2="2342523523" argName1="name" argID1="325235252" amount="-1101525.00" balance="0.00" reason="DESC:"/>
</rowset>
</result>

 

Thanks in advance.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.