getData2.php 11 KB

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