Or1g1naL Posted April 11, 2010 Share Posted April 11, 2010 function updateNode($node, $nodeID, $childNode, $cnodeValue, $xmlFile){ $dom = new DOMDocument(); $dom->load($xmlFile); $node = $dom->getElementsByTagName($node); foreach($node as $nodes){ if($nodes->getAttribute('id') == $nodeID){ $nodes->getElementsByTagName($childNode)->item(0)->nodeValue = $cnodeValue; } } $dom->save($xmlFile); } if($_POST['update'] == 'Update'){ updateNode("listing", $_POST['id'], "price", $_POST['price'], $xmlfile); updateNode("listing", $_POST['id'], "beds", $_POST['beds'], $xmlfile); updateNode("listing", $_POST['id'], "baths", $_POST['baths'], $xmlfile); updateNode("listing", $_POST['id'], "sqft", $_POST['sqft'], $xmlfile); updateNode("listing", $_POST['id'], "year", $_POST['year'], $xmlfile); updateNode("listing", $_POST['id'], "street", $_POST['street'], $xmlfile); updateNode("listing", $_POST['id'], "city", $_POST['city'], $xmlfile); updateNode("listing", $_POST['id'], "state", $_POST['state'], $xmlfile); updateNode("listing", $_POST['id'], "zip", $_POST['zip'], $xmlfile); } This is all my handy work and wonder what other more experienced people would do instead. Link to comment https://forums.phpfreaks.com/topic/198194-is-this-stupid-code/ Share on other sites More sharing options...
oni-kun Posted April 11, 2010 Share Posted April 11, 2010 Your function creates nine different objects after execution just for the purpose of editing one file, $xmlfile, You shouldn't put procedural code inside a function unless you require it to be flexible enough for other files, in this example it is redundant. Link to comment https://forums.phpfreaks.com/topic/198194-is-this-stupid-code/#findComment-1039879 Share on other sites More sharing options...
Or1g1naL Posted April 11, 2010 Author Share Posted April 11, 2010 Thank you. Link to comment https://forums.phpfreaks.com/topic/198194-is-this-stupid-code/#findComment-1039883 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.