comparison get_coordinates_for_listed_books.php @ 2:b85894a9b2dc

bug fixed: mysql query error due to updated coordinates_books table
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Tue, 24 Mar 2015 16:23:48 +0100
parents de2c442b6cbb
children 30b59e7b88c0
comparison
equal deleted inserted replaced
1:de2c442b6cbb 2:b85894a9b2dc
17 die ('Can\'t use foo : ' . mysql_error()); 17 die ('Can\'t use foo : ' . mysql_error());
18 } 18 }
19 19
20 function readCsvFile($fileName){ 20 function readCsvFile($fileName){
21 global $server_host; 21 global $server_host;
22 //$fp=fopen("../LGSearch/csv_files/".$fileName,"r");
23 $fp=fopen($server_host."LGSearch/csv_files/".$fileName,"r"); 22 $fp=fopen($server_host."LGSearch/csv_files/".$fileName,"r");
24 $data=fgetcsv($fp); 23 $data=fgetcsv($fp);
25 $columnNameMappingArray=['BOOK_ID','LEVEL1','LEVEL2', 24 $columnNameMappingArray=['BOOK_ID','LEVEL1','LEVEL2',
26 'Name','PERIOD','TimeSpan:begin','TimeSpan:end','PAGE','SECTION','CONTENT', 25 'Name','PERIOD','TimeSpan:begin','TimeSpan:end','PAGE','SECTION','CONTENT',
27 'Description']; //columns from input array/file 26 'Description']; //columns from input array/file
27 $columnNameArray=['Address','LEVEL1','LEVEL2',
28 'Name','PERIOD','TimeSpan:begin','TimeSpan:end','Longitude','Latitude',
29 'PAGE','SECTION','CONTENT',
30 'BOOK_ID','CHGIS_ID','1820_ID','1911_ID','CBDB_ID','Description']; //columns for output array/file (for map.php)
31 /*
28 $columnNameArray=['Address','ADMIN_TYPE','LEVEL1','LEVEL2', 32 $columnNameArray=['Address','ADMIN_TYPE','LEVEL1','LEVEL2',
29 'Name','PERIOD','TimeSpan:begin','TimeSpan:end','Longitude','Latitude', 33 'Name','PERIOD','TimeSpan:begin','TimeSpan:end','Longitude','Latitude',
30 'PAGE','SECTION','CONTENT', 34 'PAGE','SECTION','CONTENT',
31 'BOOK_ID','CHGIS_ID','1820_ID','1911_ID','CBDB_ID','Description']; //columns for output array/file (for map.php) 35 'BOOK_ID','CHGIS_ID','1820_ID','1911_ID','CBDB_ID','Description']; //columns for output array/file (for map.php)
36 */
32 $columnNameArray=array_flip($columnNameArray); //key, value swap in order to keep the order of the columns after merge 37 $columnNameArray=array_flip($columnNameArray); //key, value swap in order to keep the order of the columns after merge
33 $bookArray=array(); 38 $bookArray=array();
34 $count=0; 39 $count=0;
35 $line=0; 40 $line=0;
36 while(!feof($fp)){ 41 while(!feof($fp)){
52 } 57 }
53 fclose($fp); 58 fclose($fp);
54 return $bookArray; 59 return $bookArray;
55 } 60 }
56 function writeCsvFile($fileName,$bookArray){ 61 function writeCsvFile($fileName,$bookArray){
62 /*
57 $columnNameArray=['Address','ADMIN_TYPE','LEVEL1','LEVEL2', 63 $columnNameArray=['Address','ADMIN_TYPE','LEVEL1','LEVEL2',
64 'Name','PERIOD','TimeSpan:begin','TimeSpan:end','Longitude','Latitude',
65 'PAGE','SECTION','CONTENT',
66 'BOOK_ID','CHGIS_ID','1820_ID','1911_ID','CBDB_ID','Description'];
67 */
68 $columnNameArray=['Address','LEVEL1','LEVEL2',
58 'Name','PERIOD','TimeSpan:begin','TimeSpan:end','Longitude','Latitude', 69 'Name','PERIOD','TimeSpan:begin','TimeSpan:end','Longitude','Latitude',
59 'PAGE','SECTION','CONTENT', 70 'PAGE','SECTION','CONTENT',
60 'BOOK_ID','CHGIS_ID','1820_ID','1911_ID','CBDB_ID','Description']; 71 'BOOK_ID','CHGIS_ID','1820_ID','1911_ID','CBDB_ID','Description'];
61 $fp=fopen("./datasets/".$fileName,"w"); 72 $fp=fopen("./datasets/".$fileName,"w");
62 fputcsv($fp,$columnNameArray); 73 fputcsv($fp,$columnNameArray);
65 fputcsv($fp,$book); 76 fputcsv($fp,$book);
66 } 77 }
67 fclose($fp); 78 fclose($fp);
68 } 79 }
69 function getCoordinateFromDatabase($bookId){ 80 function getCoordinateFromDatabase($bookId){
81 /*
70 $query="SELECT place_name AS Address, admin_type AS ADMIN_TYPE, x AS Longitude, y AS Latitude, 82 $query="SELECT place_name AS Address, admin_type AS ADMIN_TYPE, x AS Longitude, y AS Latitude,
71 chgis_id AS CHGIS_ID, 1820_id AS 1820_ID, 1911_id AS 1911_ID, cbdb_id AS CBDB_ID 83 chgis_id AS CHGIS_ID, 1820_id AS 1820_ID, 1911_id AS 1911_ID, cbdb_id AS CBDB_ID
72 FROM coordinates_books 84 FROM coordinates_books
73 WHERE books_id='".$bookId."'"; 85 WHERE books_id='".$bookId."'";
86 */
87 $query="SELECT place_name AS Address, x AS Longitude, y AS Latitude,
88 chgis_id AS CHGIS_ID, 1820_id AS 1820_ID, 1911_id AS 1911_ID, cbdb_id AS CBDB_ID
89 FROM coordinates_books
90 WHERE books_id='".$bookId."'";
74 $result = mysql_query($query); 91 $result = mysql_query($query);
92 if (!$result) {
93 echo mysql_error();
94 return;
95 }
75 $coordinateArray=array(); 96 $coordinateArray=array();
76 while ($row = mysql_fetch_assoc($result)) { 97 while ($row = mysql_fetch_assoc($result)) {
77 $coordinateArray[]=$row; 98 $coordinateArray[]=$row;
78 } 99 }
79 return $coordinateArray; 100 return $coordinateArray;