Advertisement
atomrus1993

parse

Jan 17th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.89 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. $parser = $file->$par1->$par2;
  19. foreach ($parser as $out) {
  20. switch ($par1) {//start switch
  21. case "banks":
  22. $result = mysql_query("INSERT INTO `he78parse`.`{$par1}` (`id` ,`title` , `pictureUrl`) VALUES ('{$out['id']}', '{$out['title']}', '{$out['pictureUrl']}')");
  23. break;
  24. case "districts":
  25. $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']}')");
  26.  
  27. foreach ($out->pictures->picture as $pic) {
  28. $resultPic = mysql_query("INSERT INTO `he78parse`.`{$par1}_pictures` (`id` ,`bigUrl` , `smallUrl`) VALUES ('{$out['id']}', '{$pic['bigUrl']}', '{$pic['smallUrl']}')");
  29. }
  30. break;
  31. case "nearMetros":
  32. $result = mysql_query("INSERT INTO `he78parse`.`{$par1}` (`metro_id` ,`district_id` , `timeOnFoot` ,`timeOnCar`) VALUES ('{$out['metro_id']}', '{$out['district_id']}', '{$out['timeOnFoot']}', '{$out['timeOnCar']}')");
  33. break;
  34. case "buildings":
  35. $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']}')");
  36. break;
  37. case "mortgages":
  38. $check = mysql_fetch_object(mysql_query("select * from {$par1} where building_id = '{$out['building_id']}' and bank_id = '{$out['bank_id']}'"));
  39. if ($check==false){
  40. $result = mysql_query("INSERT INTO `he78parse`.`{$par1}` (`building_id` ,`bank_id`) VALUES ('{$out['building_id']}', '{$out['bank_id']}')");
  41. }
  42. break;
  43. case "apartments":
  44. $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']}'"));
  45. if ($check==false){
  46. $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']}')");
  47. }
  48. break;
  49. case "planes":
  50. $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']}'"));
  51. var_dump($check);
  52. if ($check==false){
  53. $result = mysql_query("INSERT INTO `he78parse`.`{$par1}` (`district` ,`roomNumber` ,`square` ,`path`) VALUES ('{$out['district']}', '{$out['roomNumber']}', '{$out['square']}', '{$out['path']}')");
  54. }
  55. break;
  56. default:
  57. $result = mysql_query("INSERT INTO `he78parse`.`{$par1}` (`id` ,`title`) VALUES ('{$out['id']}', '{$out['title']}')");
  58. }//end switch
  59. }
  60. /* view result start */
  61. if ($result==1){
  62. echo "Импорт выполнен - {$par1}";
  63. if ($par1 == "districts") {echo "<br/>Импорт выполнен - {$par1}_pictures";} echo "<br/>";
  64. }else{
  65. echo "Не удачно {$par1}".mysql_error()."<br/>";}
  66. /* view result end */
  67. }
  68.  
  69. // parser("builders");
  70. // parser("townareas");
  71. // parser("streets");
  72. // parser("metros");
  73. // parser("banks");
  74. // parser("readinesses");
  75. // parser("buildingTypes");
  76. // parser("facings");
  77. // parser("apartmentTypes");
  78. // parser("roomNumbers");
  79. // parser("districts");
  80. // parser("nearMetros");
  81. // parser("buildings");
  82. // parser("mortgages");
  83. // parser("apartments");
  84. parser("planes");
  85. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement