Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.70 KB | None | 0 0
  1.  
  2. // Create connection
  3. $conn = new mysqli($servername, $username, $password, $dbname);
  4. // Check connection
  5. if ($conn->connect_error) {
  6. die("Connection failed: " . $conn->connect_error);
  7. }
  8.  
  9. $sql = "SELECT priceLBTC FROM prices ORDER BY id DESC LIMIT 1";
  10. $result = $conn->query($sql);
  11. $bitcoinPrice = 0;
  12. if ($result->num_rows > 0) {
  13. // output data of each row
  14. while($row = $result->fetch_assoc()) {
  15. $bitcoinPrice = round($row["priceLBTC"], 2);
  16. }
  17. } else {
  18. echo "0 results";
  19. }
  20. //How can I get this data (every 120th most recent row) into the $bitcoinArray
  21. $sql2 = "SELECT priceLBTC FROM prices ORDER BY id DESC LIMIT 5760";
  22. $result2 = $conn->query($sql2);
  23. $bitcoinPriceArr = array();
  24. if ($result2->num_rows > 0) {
  25. // output data of each row
  26. $i=-1;
  27. while($row = $result2->fetch_assoc()) {
  28. $i++;
  29. if ($i%40) continue;
  30. $bitcoinPriceArr[] = round($row["priceLBTC"], 2);
  31. }
  32. } else {
  33. echo "0 results";
  34. }
  35. echo count($bitcoinPriceArr);
  36. $bitcoinArray = array_reverse($bitcoinPriceArr);
  37. $conn->close();
  38. ?>
  39.  
  40. <html>
  41. <head>
  42. <title><?php echo $bitcoinPrice; ?> USD / BTC</title>
  43. <script type="text/javascript" src="https://www.google.com/jsapi"></script>
  44. <link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>
  45. <style>
  46. body {
  47. background-color:#ffffff;
  48. padding:0px;
  49. margin:0px;
  50. }
  51. .rate {
  52. z-index: 99;
  53. font-family: 'Roboto', sans-serif;
  54. font-size: 48px;
  55. }
  56. #btc {
  57. z-index: 99;
  58. width:395px;
  59. text-align:center;
  60. display:inline-block;
  61. border-top-left-radius:5px;
  62. border-top-right-radius:5px;
  63. border:2px solid #2098d4;
  64. background-color:white;
  65. color:#2098d4;
  66. }
  67. .rateboxy {
  68. z-index: 99;
  69. display:inline-block;
  70. width:100%;
  71. float:left;
  72. }
  73. .dropdown {
  74. z-index: 99;
  75. width:24%;
  76. background-color:#2098d4;
  77. border:2px solid #2098d4;
  78. border-radius:5px;
  79. height:59px;
  80. font-size:48px;
  81. font-family: 'Roboto', sans-serif;
  82. text-align:center;
  83. color:white;
  84. float:right;
  85. display:inline-block;
  86. }
  87. .dropdown2 {
  88. z-index: 99;
  89. width:24%;
  90. background-color:#2098d4;
  91. border:2px solid #2098d4;
  92. border-radius:5px;
  93. height:59px;
  94. font-size:48px;
  95. font-family: 'Roboto', sans-serif;
  96. text-align:center;
  97. color:white;
  98. float:right;
  99. display:inline-block;
  100. }
  101. #cur {
  102. z-index: 99;
  103. width:395px;
  104. text-align:center;
  105. display:inline-block;
  106. border-radius:5px;
  107. border:2px solid #2098d4;
  108. background-color:white;
  109. color:#2098d4;
  110. }
  111. .ratesBox {
  112. z-index: 99;
  113. text-align:center;
  114. width:395px;
  115. position: absolute;
  116. height:176px;
  117. top: 50%;
  118. left: 50%;
  119. margin: -88px 0 0 -197.5px;
  120. }
  121. #equals {
  122. z-index: 99;
  123. color:#2098d4;
  124. }
  125. .bitcoin {
  126. z-index: 99;
  127. width:100%;
  128. height:60px;
  129. }
  130. .equalsBox {
  131. z-index: 99;
  132. width:74%;
  133. float:left;
  134. }
  135. .unitBox {
  136. z-index: 99;
  137. width:391px;
  138. height:40px;
  139. background-color:#29b8ff;
  140. display:block;
  141. border:2px solid #2098d4;
  142. margin-top:-3px;
  143. }
  144. .smallUnitBox {
  145. z-index: 99;
  146. background-color:#29b8ff;
  147. border-right:2px solid #2098d4;
  148. float:left;
  149. height:36px;
  150. width:96px;
  151. color:white;
  152. font-size:28px;
  153. font-family:sans-serif;
  154. border-bottom:1px solid #2098d4;
  155. line-height: 36px;
  156. cursor: pointer;
  157. cursor: hand;
  158. }
  159. .smallUnitBox2 {
  160. z-index: 99;
  161. background-color:#ed546a;
  162. float:left;
  163. height:36px;
  164. width:96px;
  165. color:white;
  166. font-size:28px;
  167. font-family:sans-serif;
  168. border-bottom:1px solid #2098d4;
  169. padding-right:1px;
  170. line-height: 36px;
  171. cursor: pointer;
  172. cursor: hand;
  173. }
  174. #chart_div {
  175. z-index:-1;
  176. height:100%;
  177. width:100%;
  178. }
  179. input:focus,
  180. select:focus,
  181. textarea:focus,
  182. button:focus {
  183. outline: none;
  184. }
  185. </style>
  186. </head>
  187. <body>
  188. <script>
  189. var SAT = 0.00000001;
  190. var BIT = 0.000001;
  191. var MBIT = 0.001;
  192. var BTC = 1;
  193. var currentUnit = BTC;
  194. function changeColor(div) {
  195. document.getElementById('satoshiBox').style.background='#29b8ff';
  196. document.getElementById('bitBox').style.background='#29b8ff';
  197. document.getElementById('BTCBox').style.background='#29b8ff';
  198. document.getElementById('mBTCBox').style.background='#29b8ff';
  199.  
  200. document.getElementById(div).style.background='#ed546a';
  201. }
  202. function satoshiConvert(input) {
  203. if (currentUnit != SAT) {
  204. input.value = (convertBTC(input.value) / SAT).toFixed(0);
  205. currentUnit = SAT;
  206. changeColor('satoshiBox');
  207. btcConvert(input);
  208. }
  209. }
  210. function bitConvert(input) {
  211. if (currentUnit != BIT) {
  212. input.value = (convertBTC(input.value) / BIT).toFixed(2);
  213. currentUnit = BIT;
  214. changeColor('bitBox');
  215. btcConvert(input);
  216. }
  217. }
  218. function mBTCConvert(input) {
  219. if (currentUnit != MBIT) {
  220. input.value = (convertBTC(input.value) / MBIT).toFixed(4);
  221. currentUnit = MBIT;
  222. changeColor('mBTCBox');
  223. btcConvert(input);
  224. }
  225. }
  226. function bitcoinConversion(input) {
  227. if (currentUnit != BTC) {
  228. input.value = (convertBTC(input.value) / BTC).toFixed(8);
  229. currentUnit = BTC;
  230. changeColor('BTCBox');
  231. btcConvert(input);
  232. }
  233. }
  234. function convertBTC(value) {
  235. if (currentUnit == SAT) {
  236. value = value * SAT;
  237. return value;
  238. } else if (currentUnit == BIT) {
  239. value = value * BIT;
  240. return value;
  241. } else if (currentUnit == MBIT) {
  242. value = value * MBIT;
  243. return value;
  244. } else if (currentUnit == BTC) {
  245. return value;
  246. }
  247. }
  248. function btcConvert(input) {
  249. if(isNaN(input.value)) {
  250. document.getElementById('equals').innerHTML = "enter a number";
  251. }else {
  252. document.getElementById('equals').innerHTML = "=";
  253. }
  254. var price = "<?php echo $bitcoinPrice; ?>";
  255. var out = convertBTC(input.value) * price;
  256. var co = document.getElementById('cur');
  257. cur.value = out.toFixed(2);
  258. }
  259. function usdConvert(input) {
  260. if(isNaN(input.value)) {
  261. document.getElementById('equals').innerHTML = "enter a number";
  262. }else {
  263. document.getElementById('equals').innerHTML = "=";
  264. }
  265. var price2 = "<?php echo $bitcoinPrice; ?>";
  266. var out2 = input.value / (price2 * currentUnit);
  267. var co2 = document.getElementById('btc');
  268. if (currentUnit == SAT) {
  269. var rounding = 0;
  270. } else if (currentUnit == BIT) {
  271. var rounding = 2;
  272. } else if (currentUnit == MBIT) {
  273. var rounding = 4;
  274. } else {
  275. var rounding = 8;
  276. }
  277. btc.value = out2.toFixed(rounding);
  278. }
  279. google.load('visualization', '1', {packages: ['corechart', 'line']});
  280. google.setOnLoadCallback(drawAxisTickColors);
  281.  
  282. function drawAxisTickColors() {
  283. var data = new google.visualization.DataTable();
  284. data.addColumn('number', 'X');
  285. data.addColumn('number', 'Price');
  286.  
  287. data.addRows([
  288. <?
  289. $i = 0;
  290.  
  291. foreach ($bitcoinPriceArr as $v) {
  292. echo "[".strval($i+1).", ".$v."]";
  293. $i++;
  294.  
  295. if ($i < count($bitcoinPriceArr)) {
  296. echo ", ";
  297. }
  298. }
  299. ?>
  300. ]);
  301. var options = {
  302. chartArea: {
  303. left: 0,
  304. top: 0,
  305. right: 0,
  306. bottom: 0,
  307. width: "100%",
  308. height: "100%"
  309. },
  310. hAxis: {
  311. textPosition: 'none',
  312. baselineColor: 'none',
  313. gridlines: {
  314. color: 'none'
  315. },
  316. },
  317. vAxis: {
  318. textPosition: 'none',
  319. baselineColor: 'none',
  320. gridlines: {
  321. color: 'none'
  322. }
  323. },
  324. colors: ['blue', '#ffffff'],
  325. legend: 'none'
  326. };
  327. var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
  328. chart.draw(data, options);
  329. }
  330. </script>
  331. <center>
  332. <div class = "ratesBox">
  333. <div class = "bitcoin">
  334. <div class = "rateboxy"><input value = "1" type="text" name = "btc" id="btc" class="rate" onchange="btcConvert(this);" onkeyup ="btcConvert(this);"/></div>
  335. </div>
  336. <div class= "unitBox">
  337. <div class = "smallUnitBox" onclick="satoshiConvert(btc);" id="satoshiBox">sat</div>
  338. <div class = "smallUnitBox" onclick="bitConvert(btc);" id="bitBox">bit</div>
  339. <div class = "smallUnitBox" onclick="mBTCConvert(btc);"id="mBTCBox">mBTC</div>
  340. <div class = "smallUnitBox2" onclick="bitcoinConversion(btc);" id="BTCBox">BTC</div>
  341. </div>
  342. <p id = "equals">=</p>
  343. <div class = "rateboxy"><input value = "<?php echo $bitcoinPrice; ?>"type="text" name="cur" id="cur" class="rate" onchange="usdConvert(this);" onkeyup ="usdConvert(this);"/></div>
  344. </div>
  345. </center>
  346. <div id="chart_div"></div>
  347. </body>
  348. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement