Jump to content

Multiple Updates into MYSQL


GalaxyTramp

Recommended Posts

Ok this has been driving me crazy for days now. I need to update my DB with multiple data parsed from an XML feed. I need some help in putting together the query.

 

Currently I have:

$xml= 'test-feed.xml'; // URL for feed.



try{
  $feed = new SimpleXMLElement($xml, null, true);
}catch(Exception $e){
  echo $e->getMessage();
  exit;
}


$sqlxml = "";
$arr = array();

foreach($feed->property as $property) {

$propertyid = (string)$property->id;

foreach($property->images->image as $image) {
$i = 0;
  $url = (string)$image->url;
  $arr[] = "UPDATE property SET url = '$url' WHERE prop_id = '$propertyid', ";
$i++; 
  

}

}

foreach($arr as $result) $sql .= $result;


$sql = rtrim($sql, ",");

echo $sql;


if(!mysql_query($sql)){
  echo '<h1 style="color: red;">Error</h1><p>', mysql_error(), '</p>';
}
else
{

  echo '<h1 style="color: red;">Property data successfully added to database!</h1>';
}

 

This structures the query correctly for a single update but repeats it which then throws a MYSQL Syntax error. I am not sure of the correct syntax to use for multiple inserts??

 

What I get returned at the moment is:

 

UPDATE property SET url = 'ImageId=X1000245' WHERE prop_id = 'A1234', UPDATE property SET url = 'ImageId=X1000296' WHERE prop_id = 'A1234', UPDATE property SET url = 'ImageId=P3&ImgId=X1000237' WHERE prop_id = 'ABC1234',

 

Need some intervention guys

 

Thanks in advance

 

GT

Link to comment
https://forums.phpfreaks.com/topic/229790-multiple-updates-into-mysql/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.