GalaxyTramp Posted March 6, 2011 Share Posted March 6, 2011 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 More sharing options...
mattal999 Posted March 6, 2011 Share Posted March 6, 2011 Edit: Look at the response below. Link to comment https://forums.phpfreaks.com/topic/229790-multiple-updates-into-mysql/#findComment-1183644 Share on other sites More sharing options...
Pikachu2000 Posted March 6, 2011 Share Posted March 6, 2011 You can't run multiple queries with the mysql extension. It's appears to be possible with the mysqli extension, using , although I've never used that particular function. Link to comment https://forums.phpfreaks.com/topic/229790-multiple-updates-into-mysql/#findComment-1183645 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.