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);
- }
- // var_dump($file->districts->district->pictures);
- $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']}')");
- 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":
- $result = mysql_query("INSERT INTO `he78parse`.`{$par1}` (`building_id` ,`bank_id`) VALUES ('{$out['building_id']}', '{$out['bank_id']}')");
- break;
- case "apartments":
- $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":
- $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
- }
- if ($result==1){echo "Импорт выполнен - {$par1}<br/>";}else{echo "Не удачно {$par1}".mysql_error()."<br/>";}
- }
- parser("builders");
- parser("townareas");
- parser("streets");
- parser("metros");
- parser("banks");
- parser("readinesses");
- parser("buildingTypes");
- parser("facings");
- parser("apartmentTypes");
- parser("roomNumbers");
- parser("districts");
- // parser("pictures"); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- parser("nearMetros");
- parser("buildings");
- // parser("mortgages");
- // parser("apartments");
- parser("planes");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement