getData2.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <?php
  2. include "connectSQL.php";
  3. if (isset($_GET['q'])) {
  4. echo "<table id='dataTable' class='display' width='100%'>";
  5. $wellName = $_GET['q'];
  6. //ELP's only
  7. $wellNameA = str_replace("A", "-1A", $wellName);
  8. if(contains($wellName, "ELP") ||contains($wellName, "OW") || contains($wellName, "SM") || contains($wellName, "SB") || contains($wellName, "SBM") || contains($wellName, "VG") || contains($wellName, "HM")){
  9. if(contains($wellName, "OW")){
  10. $sqlOW = "SELECT * FROM [C3].[dbo].[OWdata]";
  11. $fetchResult = sqlsrv_query($conn, $sqlOW);
  12. }else if(contains($wellName, "SM")){
  13. $sqlSM = "SELECT * FROM [C3].[dbo].[SMdata]";
  14. $fetchResult = sqlsrv_query($conn, $sqlSM);
  15. }else if(contains($wellName, "SBM")){
  16. $sqlSBM = "SELECT * FROM [C3].[dbo].[SBMdata]";
  17. $fetchResult = sqlsrv_query($conn, $sqlSBM);
  18. }else if(contains($wellName, "SB")){
  19. $sqlSB = "SELECT * FROM [C3].[dbo].[SBdata]";
  20. $fetchResult = sqlsrv_query($conn, $sqlSB);
  21. }else if(contains($wellName, "VG")){
  22. $sqlVG = "SELECT * FROM [C3].[dbo].[VGdata]";
  23. $fetchResult = sqlsrv_query($conn, $sqlVG);
  24. }else if(contains($wellName, "HM")){
  25. if(!contains($wellName, "HM-")){
  26. $wellName = str_replace("HM", "HM_", $wellName);
  27. }
  28. $sqlHM = "SELECT * FROM [C3].[dbo].[HMdata]";
  29. $fetchResult = sqlsrv_query($conn, $sqlHM);
  30. }else if(contains($wellName, "ELP")){
  31. $sqlELP = "SELECT * FROM [C3].[dbo].[ELPdata]";
  32. $fetchResult = sqlsrv_query($conn, $sqlELP);
  33. }
  34. //Table's header and footer
  35. echo "<thead>
  36. <tr>
  37. <th>測量日期</th>
  38. <th>".str_replace("_", "-", $wellName)."</th>
  39. </tr>
  40. </thead>
  41. <tfoot>
  42. <tr>
  43. <th>測量日期</th>
  44. <th>".str_replace("_", "-", $wellName)."</th>
  45. </tr>
  46. </tfoot>";
  47. }else if(contains($wellName, "SID") || contains($wellName, "SIS")){
  48. $fetchResult = fetchSISSID($wellName, $conn);
  49. while($row = sqlsrv_fetch_array($fetchResult)){
  50. $columnCount = count(array_filter($row))/2-1;
  51. }
  52. $str = tHeaderFooter($columnCount);
  53. echo "
  54. <thead>
  55. <tr>
  56. <th>測量日期</th>
  57. <th>觀測深度0</th>
  58. ".$str."
  59. </tr>
  60. </thead>
  61. <tfoot>
  62. <tr>
  63. <th>測量日期</th>
  64. <th>觀測深度0</th>
  65. ".$str."
  66. </tr>
  67. </tfoot>";
  68. $fetchResult = fetchSISSID($wellName, $conn);
  69. }else if(contains($wellName, "TI")){
  70. $sqlTI = "SELECT * FROM [C3].[dbo].[TIdata]";
  71. $fetchResult = sqlsrv_query($conn, $sqlTI);
  72. echo "<thead>
  73. <tr>
  74. <th>測量日期</th>
  75. <th>".$wellName."(1~3向)</th>
  76. <th>".$wellName."(2~4向)</th>
  77. </tr>
  78. </thead>
  79. <tfoot>
  80. <tr>
  81. <th>測量日期</th>
  82. <th>".$wellName."(1~3向)</th>
  83. <th>".$wellName."(2~4向)</th>
  84. </tr>
  85. </tfoot>";
  86. }else if(contains($wellName, "RS")){
  87. $sqlRS = "SELECT * FROM [C3].[dbo].[RSdata]";
  88. $fetchResult = sqlsrv_query($conn, $sqlRS);
  89. echo "<thead>
  90. <tr>
  91. <th>測量日期</th>
  92. <th>".$wellName."-A</th>
  93. <th>".$wellName."-B</th>
  94. <th>".$wellName."-C</th>
  95. <th>".$wellName."-D</th>
  96. <th>".$wellName."-E</th>
  97. <th>".$wellName."-F</th>
  98. </tr>
  99. </thead>
  100. <tfoot>
  101. <tr>
  102. <th>測量日期</th>
  103. <th>".$wellName."-A</th>
  104. <th>".$wellName."-B</th>
  105. <th>".$wellName."-C</th>
  106. <th>".$wellName."-D</th>
  107. <th>".$wellName."-E</th>
  108. <th>".$wellName."-F</th>
  109. </tr>
  110. </tfoot>";
  111. }
  112. echo "<tbody>";
  113. while($row = sqlsrv_fetch_array($fetchResult)){
  114. echo "<tr>";
  115. echo "<td>";
  116. echo $row["m_date"];
  117. echo "</td>";
  118. if(contains($wellName, "OW") || contains($wellName, "ELP") || contains($wellName, "SM") || contains($wellName, "SB") || contains($wellName, "SBM") || contains($wellName, "VG") || contains($wellName, "HM")){
  119. $columnName = str_replace("-", "_", $wellName);
  120. $columnNameA = str_replace("-", "_", $wellNameA);
  121. fontHead($row[$columnName], $wellName);
  122. echo $row[$columnName];
  123. fontFoot($row[$columnName], $wellName);
  124. /*if(contains($wellNameA, "A")){
  125. fontHead($row[$columnNameA], $wellNameA);
  126. echo $row[$columnNameA];
  127. fontFoot($row[$columnNameA], $wellNameA);
  128. }else if(contains($wellName, "ELP-1")){
  129. fontHead($row["ELP_1_1"], "ELP-1-1");
  130. echo $row["ELP_1_1"];
  131. fontFoot($row["ELP_1_1"], "ELP-1-1");
  132. }else if(contains($wellName, "ELP-7")){
  133. fontHead($row["ELP_7_1"], "ELP-7-1");
  134. echo $row["ELP_7_1"];
  135. fontFoot($row["ELP_7_1"], "ELP-7-1");
  136. }*/
  137. }else if(contains($wellName, "SID") || contains($wellName, "SIS")){
  138. displayValue($row, $wellName, $columnCount);
  139. }else if(contains($wellName, "TI")){
  140. $columnName = str_replace("-", "_", $wellName);
  141. $columnName13 = $columnName;
  142. $columnName24 = $columnName."(2~4)";
  143. fontHead($row[$columnName13], $wellName);
  144. echo $row[$columnName13];
  145. fontFoot($row[$columnName13], $wellName);
  146. fontHead($row[$columnName24], $wellName);
  147. echo $row[$columnName24];
  148. fontFoot($row[$columnName24], $wellName);
  149. }else if(contains($wellName, "RS")){
  150. $columnName = str_replace("-", "_", $wellName);
  151. $columnNameA = $columnName."_A";
  152. $columnNameB = $columnName."_B";
  153. $columnNameC = $columnName."_C";
  154. $columnNameD = $columnName."_D";
  155. $columnNameE = $columnName."_E";
  156. $columnNameF = $columnName."_F";
  157. fontHead($row[$columnNameA], $wellName);
  158. echo $row[$columnNameA];
  159. fontFoot($row[$columnNameA], $wellName);
  160. fontHead($row[$columnNameB], $wellName);
  161. echo $row[$columnNameB];
  162. fontFoot($row[$columnNameB], $wellName);
  163. fontHead($row[$columnNameC], $wellName);
  164. echo $row[$columnNameC];
  165. fontFoot($row[$columnNameC], $wellName);
  166. fontHead($row[$columnNameD], $wellName);
  167. echo $row[$columnNameD];
  168. fontFoot($row[$columnNameD], $wellName);
  169. fontHead($row[$columnNameE], $wellName);
  170. echo $row[$columnNameE];
  171. fontFoot($row[$columnNameE], $wellName);
  172. fontHead($row[$columnNameF], $wellName);
  173. echo $row[$columnNameF];
  174. fontFoot($row[$columnNameF], $wellName);
  175. }
  176. echo "</tr>";
  177. }
  178. echo "</tbody>";
  179. echo "</table>";
  180. sqlsrv_close($conn);
  181. }
  182. //Turn the illegal value's color red(Header)
  183. function fontHead($row, $wellName){
  184. $e_value = 0;
  185. $e_value_n = 0;
  186. if(contains($wellName, "OW")){
  187. $e_value = -2;
  188. }else if(contains($wellName, "ELP")){
  189. $e_value = -7.9;
  190. }else if(contains($wellName, "SID") || contains($wellName, "SIS")){
  191. $e_value = 5.2;
  192. }else if(contains($wellName, "TI")){
  193. $e_value = 0.00106;
  194. $e_value_n = -0.00106;
  195. }else if(contains($wellName, "RS")){
  196. $e_value = 2000;
  197. $e_value_n = -2000;
  198. }else if(contains($wellName, "SM")){
  199. $e_value = 25;
  200. }else if(contains($wellName, "SBM")){
  201. $e_value = 9.5;
  202. $e_value_n = -9.5;
  203. }else if(contains($wellName, "SB")){
  204. $e_value = 0.0008;
  205. $e_value_n = -0.0008;
  206. }else if(contains($wellName, "VG")){
  207. $e_value = 110;
  208. }else if(contains($wellName, "HM")){
  209. $e_value = 25;
  210. }
  211. /*if(contains($wellName, "OW") || contains($wellName, "ELP") || contains($wellName, "SIS") || contains($wellName, "SID") || contains($wellName, "SM") || contains($wellName, "VG") || contains($wellName, "HM")){
  212. if($row > $e_value){
  213. echo "<td>";
  214. //echo "<font color='red'>";
  215. }else{
  216. echo "<td>";
  217. }
  218. }else if(contains($wellName, "TI") || contains($wellName, "RS") || contains($wellName, "SBM") || contains($wellName, "SB")){
  219. if($row > $e_value || $row < $e_value_n){
  220. echo "<td>";
  221. //echo "<font color='red'>";
  222. }else{
  223. echo "<td>";
  224. }
  225. }*/
  226. echo "<td>";
  227. }
  228. //Turn the illegal value's color red(Footer)
  229. function fontFoot($row, $wellName){
  230. $e_value = 0;
  231. $e_value_n = 0;
  232. if(contains($wellName, "OW")){
  233. $e_value = -2;
  234. }else if(contains($wellName, "ELP")){
  235. $e_value = -7.9;
  236. }else if(contains($wellName, "SID") || contains($wellName, "SIS")){
  237. $e_value = 5.2;
  238. }else if(contains($wellName, "TI")){
  239. $e_value = 0.00106;
  240. $e_value_n = -0.00106;
  241. }else if(contains($wellName, "RS")){
  242. $e_value = 2000;
  243. $e_value_n = -2000;
  244. }else if(contains($wellName, "SM")){
  245. $e_value = 25;
  246. }else if(contains($wellName, "SBM")){
  247. $e_value = 9.5;
  248. $e_value_n = -9.5;
  249. }else if(contains($wellName, "SB")){
  250. $e_value = 0.0008;
  251. $e_value_n = -0.0008;
  252. }else if(contains($wellName, "VG")){
  253. $e_value = 110;
  254. }else if(contains($wellName, "HM")){
  255. $e_value = 25;
  256. }
  257. if(contains($wellName, "OW") || contains($wellName, "ELP") || contains($wellName, "SIS") || contains($wellName, "SID") || contains($wellName, "SM") || contains($wellName, "VG") || contains($wellName, "HM")){
  258. if($row > $e_value){
  259. echo "</font>";
  260. echo "</td>";
  261. }else{
  262. echo "</td>";
  263. }
  264. }else if(contains($wellName, "TI") || contains($wellName, "RS") || contains($wellName, "SBM") || contains($wellName, "SB")){
  265. if($row > $e_value || $row < $e_value_n){
  266. echo "</font>";
  267. echo "</td>";
  268. }else{
  269. echo "</td>";
  270. }
  271. }
  272. }
  273. //Check if string contains your designated word
  274. function contains($str, $target)
  275. {
  276. if (stripos($str, $target) !== false){
  277. return true;
  278. }
  279. return false;
  280. }
  281. function fetchSISSID($wellName, $conn){
  282. if(contains($wellName, "SID")){
  283. $sqlSID = "SELECT * FROM [C3].[dbo].[SIDdata] WHERE e_name = '".$wellName."'";
  284. $fetchResult = sqlsrv_query($conn, $sqlSID);
  285. }else if(contains($wellName, "SIS")){
  286. $sqlSIS = "SELECT * FROM [C3].[dbo].[SISdata] WHERE e_name = '".$wellName."'";
  287. $fetchResult = sqlsrv_query($conn, $sqlSIS);
  288. }
  289. return $fetchResult;
  290. }
  291. //SIS SID's header footer
  292. function tHeaderFooter($columnCount){
  293. $str = "";
  294. for($i = 1; $i < $columnCount; $i++){
  295. $str .= "<th>觀測深度-".($i/2)."</th>";
  296. }
  297. return $str;
  298. }
  299. //SIS SID's value display
  300. function displayValue($row, $wellName, $columnCount){
  301. for($i = 0; $i < $columnCount; $i++){
  302. $str = "depth_".($i);
  303. fontHead($row[$str], $wellName);
  304. echo $row[$str];
  305. fontFoot($row[$str], $wellName);
  306. }
  307. }