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