Advertisement
atomrus1993

Untitled

Jan 16th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.50 KB | None | 0 0
  1. <?php
  2. include 'db.php';
  3. $file = simplexml_load_file("file.xml");
  4.  
  5. function check ($par1,$par2,$par3){
  6.     $temp = mysql_query("Select * from {$par1} where {$par2} = '{$par3}'");
  7.     $give = mysql_fetch_object($temp);
  8.     return $give->$par2;
  9. }
  10.  
  11. function parser ($par1){
  12.     global $file;
  13.     if($par1!='readinesses'){
  14.         $par2 = substr($par1, 0, -1);
  15.     }else{
  16.         $par2 = substr($par1, 0, -2);
  17.     }
  18.     // var_dump($file->districts->district->pictures);
  19.     $parser = $file->$par1->$par2;
  20.     foreach ($parser as $out) {
  21.         switch ($par1) {//start switch
  22.             case "banks":
  23.                 $result = mysql_query("INSERT INTO  `he78parse`.`{$par1}` (`id` ,`title` , `pictureUrl`) VALUES ('{$out['id']}', '{$out['title']}', '{$out['pictureUrl']}')");
  24.             break;
  25.             case "districts":  
  26.                 $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']}')");
  27.             break;
  28.             case "nearMetros":
  29.                 $result = mysql_query("INSERT INTO  `he78parse`.`{$par1}` (`metro_id` ,`district_id` , `timeOnFoot` ,`timeOnCar`) VALUES ('{$out['metro_id']}', '{$out['district_id']}', '{$out['timeOnFoot']}', '{$out['timeOnCar']}')");
  30.             break;
  31.             case "buildings":
  32.                 $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']}')");
  33.             break;
  34.             case "mortgages":
  35.                 $result = mysql_query("INSERT INTO  `he78parse`.`{$par1}` (`building_id` ,`bank_id`) VALUES ('{$out['building_id']}', '{$out['bank_id']}')");
  36.             break;
  37.             case "apartments":
  38.                 $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']}')");
  39.             break;
  40.             case "planes":
  41.                 $result = mysql_query("INSERT INTO  `he78parse`.`{$par1}` (`district` ,`roomNumber` ,`square` ,`path`) VALUES ('{$out['district']}', '{$out['roomNumber']}', '{$out['square']}', '{$out['path']}')");
  42.             break;
  43.             default:
  44.                 $result = mysql_query("INSERT INTO  `he78parse`.`{$par1}` (`id` ,`title`) VALUES ('{$out['id']}', '{$out['title']}')");
  45.             }//end switch
  46.         }
  47.     if ($result==1){echo "Импорт выполнен - {$par1}<br/>";}else{echo "Не удачно {$par1}".mysql_error()."<br/>";}
  48. }
  49. parser("builders");
  50. parser("townareas");
  51. parser("streets");
  52. parser("metros");
  53. parser("banks");
  54. parser("readinesses");
  55. parser("buildingTypes");
  56. parser("facings");
  57. parser("apartmentTypes");
  58. parser("roomNumbers");
  59. parser("districts");
  60. // parser("pictures"); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  61. parser("nearMetros");
  62. parser("buildings");
  63. // parser("mortgages");
  64. // parser("apartments");
  65. parser("planes");
  66. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement