Sign in to follow this  
Followers 0

extract xml id's using php

3 posts in this topic

Hi all,


hope you can help


I have an xml document that is loading nicely into a database, with the exception of the images within the image tags. See structure of xml below


    <name>Name here</name>

    <description>​Description here etc etc</description>


    <img id="0">img url 1 here </img>
    <img id="1">img url 2 here </img>



I would like to get the image url's into the database with the | to separate them if possible.


Below is the php script I am using get the info from xml into database.

It works well for all fields except the images as they are id's with the main image tag




trigger_error('Error reading XML file',E_USER_ERROR);


foreach ($xml as $syn)


$name = $syn->name; 

$description = $syn->description; 

$images = $syn->img[]; 

$sql    = "INSERT INTO Benek









$query  = mysql_query($sql);


if (!$query)


    echo ('Error: ' . mysql_error());




    echo "Record added";




Thanks for your time.



Share this post

Link to post
Share on other sites

I would start with $syn->images, then loop through the children of that node and get the value for each one.

Share this post

Link to post
Share on other sites

Hi thanks for your reply. That was what I did initially, but it returned no values. Possibly due to poor syntax on my part.

I have found a small piece of javascript that grabs the child elements from the parent by id, and think I may be able to update the database with the image urls after the initial values have been inserted.

Seems a bit of a convoluted approach, but that's where I am at.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0