Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include 'db.php';
- $file = simplexml_load_file("file.xml");
- function check ($par1,$par2,$par3){
- $temp = mysql_query("Select * from {$par1} where {$par2} = '{$par3}'");
- $give = mysql_fetch_object($temp);
- return $give->$par2;
- }
- function parser ($par1){
- global $file;
- if($par1!='readinesses'){
- $par2 = substr($par1, 0, -1);
- }else{
- $par2 = substr($par1, 0, -2);
- }
- $parser = $file->$par1->$par2;
- foreach ($parser as $out) {
- switch ($par1) {//start switch
- case "banks":
- $result = mysql_query("INSERT INTO `he78parse`.`{$par1}` (`id` ,`title` , `pictureUrl`) VALUES ('{$out['id']}', '{$out['title']}', '{$out['pictureUrl']}')");
- break;
- case "districts":
- $result = mysql_query("INSERT INTO `he78parse`.`{$par1}` (`id` ,`title` , `town` ,`townarea` ,`latitude` ,`longitude`) VALUES ('{$out['id']}', '{$out['title']}', '{$out['town']}', '{$out['townarea']}', '{$out['latitude']}', '{$out['longitude']}')");
- foreach ($out->pictures->picture as $pic) {
- $resultPic = mysql_query("INSERT INTO `he78parse`.`{$par1}_pictures` (`id` ,`bigUrl` , `smallUrl`) VALUES ('{$out['id']}', '{$pic['bigUrl']}', '{$pic['smallUrl']}')");
- }
- break;
- case "nearMetros":
- $result = mysql_query("INSERT INTO `he78parse`.`{$par1}` (`metro_id` ,`district_id` , `timeOnFoot` ,`timeOnCar`) VALUES ('{$out['metro_id']}', '{$out['district_id']}', '{$out['timeOnFoot']}', '{$out['timeOnCar']}')");
- break;
- case "buildings":
- $result = mysql_query("INSERT INTO `he78parse`.`{$par1}` (`id` ,`builder` , `district` ,`corp` ,`endingYear` ,`endingQuarter` ,`floors` ,`sections` ,`street` ,`readiness` ,`buildingType`) VALUES ('{$out['id']}', '{$out['builder']}', '{$out['district']}', '{$out['corp']}', '{$out['endingYear']}', '{$out['endingQuarter']}', '{$out['floors']}', '{$out['sections']}', '{$out['street']}', '{$out['readiness']}', '{$out['buildingType']}')");
- break;
- case "mortgages":
- $check = mysql_fetch_object(mysql_query("select * from {$par1} where building_id = '{$out['building_id']}' and bank_id = '{$out['bank_id']}'"));
- if ($check==false){
- $result = mysql_query("INSERT INTO `he78parse`.`{$par1}` (`building_id` ,`bank_id`) VALUES ('{$out['building_id']}', '{$out['bank_id']}')");
- }
- break;
- case "apartments":
- $check = mysql_fetch_object(mysql_query("select * from {$par1} where id = '{$out['id']}' and building = '{$out['building']}' and roomNumber = '{$out['roomNumber']}' and facing = '{$out['facing']}' and apartmentType = '{$out['apartmentType']}' and floor = '{$out['floor']}' and square = '{$out['square']}' and livingSquare = '{$out['livingSquare']}' and kitchenSquare = '{$out['kitchenSquare']}' and apartmentPrice = '{$out['apartmentPrice']}' and meterPrice = '{$out['meterPrice']}' and agency_id = '{$out['agency_id']}' and planePicUrl = '{$out['planePicUrl']}'"));
- if ($check==false){
- $result = mysql_query("INSERT INTO `he78parse`.`{$par1}` (`id` ,`building` ,`roomNumber` ,`facing` ,`apartmentType` ,`floor` ,`square` ,`livingSquare` ,`kitchenSquare` ,`apartmentPrice` ,`meterPrice` ,`agency_id` ,`planePicUrl`) VALUES ('{$out['id']}', '{$out['building']}', '{$out['roomNumber']}', '{$out['facing']}', '{$out['apartmentType']}', '{$out['floor']}', '{$out['square']}', '{$out['livingSquare']}', '{$out['kitchenSquare']}', '{$out['apartmentPrice']}', '{$out['meterPrice']}', '{$out['agency_id']}', '{$out['planePicUrl']}')");
- }
- break;
- case "planes":
- $check = mysql_fetch_object(mysql_query("select * from {$par1} where `district` = '{$out['district']}' and `roomNumber` = '{$out['roomNumber']}' and `square` = '{$out['square']}' and `path` = '{$out['path']}'"));
- var_dump($check);
- if ($check==false){
- $result = mysql_query("INSERT INTO `he78parse`.`{$par1}` (`district` ,`roomNumber` ,`square` ,`path`) VALUES ('{$out['district']}', '{$out['roomNumber']}', '{$out['square']}', '{$out['path']}')");
- }
- break;
- default:
- $result = mysql_query("INSERT INTO `he78parse`.`{$par1}` (`id` ,`title`) VALUES ('{$out['id']}', '{$out['title']}')");
- }//end switch
- }
- /* view result start */
- if ($result==1){
- echo "Импорт выполнен - {$par1}";
- if ($par1 == "districts") {echo "<br/>Импорт выполнен - {$par1}_pictures";} echo "<br/>";
- }else{
- echo "Не удачно {$par1}".mysql_error()."<br/>";}
- /* view result end */
- }
- // parser("builders");
- // parser("townareas");
- // parser("streets");
- // parser("metros");
- // parser("banks");
- // parser("readinesses");
- // parser("buildingTypes");
- // parser("facings");
- // parser("apartmentTypes");
- // parser("roomNumbers");
- // parser("districts");
- // parser("nearMetros");
- // parser("buildings");
- // parser("mortgages");
- // parser("apartments");
- parser("planes");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement