getData2.php 11 KB

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