I am trying to import xml data into a mysql table. I have the below fields to be Imported:
reference price category type city property imgurl1 imgurl2The problem is that the number of <imgurl>(url to image file)
is not the same. Below is the code:
$conn = mysql_connect($hostname, $username, $password);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname,$conn) or die( mysql_error() );
$xml = simplexml_load_file('http://astonpearlemail.net/feeds/feedsmall.xml');
$data = $fields = array();
foreach ($xml->xpath('listing') as $listing) {
$fields = array_keys((array)($listing));
$data[] = '("' . join('", "', (array)$listing) . '")';
}
$sql = "INSERT INTO ap_prop (" . join(', ', $fields) . ") VALUES
" ;
$sql .= join (",
", $data);
$result1 = mysql_query($sql,$conn);
echo "<pre>$sql</pre>"
Please suggest how I can import the varying number of imgurl
.
Thanks in advance