Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "SELECT priceLBTC FROM prices ORDER BY id DESC LIMIT 1";
- $result = $conn->query($sql);
- $bitcoinPrice = 0;
- if ($result->num_rows > 0) {
- // output data of each row
- while($row = $result->fetch_assoc()) {
- $bitcoinPrice = round($row["priceLBTC"], 2);
- }
- } else {
- echo "0 results";
- }
- //How can I get this data (every 120th most recent row) into the $bitcoinArray
- $sql2 = "SELECT priceLBTC FROM prices ORDER BY id DESC LIMIT 5760";
- $result2 = $conn->query($sql2);
- $bitcoinPriceArr = array();
- if ($result2->num_rows > 0) {
- // output data of each row
- $i=-1;
- while($row = $result2->fetch_assoc()) {
- $i++;
- if ($i%40) continue;
- $bitcoinPriceArr[] = round($row["priceLBTC"], 2);
- }
- } else {
- echo "0 results";
- }
- echo count($bitcoinPriceArr);
- $bitcoinArray = array_reverse($bitcoinPriceArr);
- $conn->close();
- ?>
- <html>
- <head>
- <title><?php echo $bitcoinPrice; ?> USD / BTC</title>
- <script type="text/javascript" src="https://www.google.com/jsapi"></script>
- <link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>
- <style>
- body {
- background-color:#ffffff;
- padding:0px;
- margin:0px;
- }
- .rate {
- z-index: 99;
- font-family: 'Roboto', sans-serif;
- font-size: 48px;
- }
- #btc {
- z-index: 99;
- width:395px;
- text-align:center;
- display:inline-block;
- border-top-left-radius:5px;
- border-top-right-radius:5px;
- border:2px solid #2098d4;
- background-color:white;
- color:#2098d4;
- }
- .rateboxy {
- z-index: 99;
- display:inline-block;
- width:100%;
- float:left;
- }
- .dropdown {
- z-index: 99;
- width:24%;
- background-color:#2098d4;
- border:2px solid #2098d4;
- border-radius:5px;
- height:59px;
- font-size:48px;
- font-family: 'Roboto', sans-serif;
- text-align:center;
- color:white;
- float:right;
- display:inline-block;
- }
- .dropdown2 {
- z-index: 99;
- width:24%;
- background-color:#2098d4;
- border:2px solid #2098d4;
- border-radius:5px;
- height:59px;
- font-size:48px;
- font-family: 'Roboto', sans-serif;
- text-align:center;
- color:white;
- float:right;
- display:inline-block;
- }
- #cur {
- z-index: 99;
- width:395px;
- text-align:center;
- display:inline-block;
- border-radius:5px;
- border:2px solid #2098d4;
- background-color:white;
- color:#2098d4;
- }
- .ratesBox {
- z-index: 99;
- text-align:center;
- width:395px;
- position: absolute;
- height:176px;
- top: 50%;
- left: 50%;
- margin: -88px 0 0 -197.5px;
- }
- #equals {
- z-index: 99;
- color:#2098d4;
- }
- .bitcoin {
- z-index: 99;
- width:100%;
- height:60px;
- }
- .equalsBox {
- z-index: 99;
- width:74%;
- float:left;
- }
- .unitBox {
- z-index: 99;
- width:391px;
- height:40px;
- background-color:#29b8ff;
- display:block;
- border:2px solid #2098d4;
- margin-top:-3px;
- }
- .smallUnitBox {
- z-index: 99;
- background-color:#29b8ff;
- border-right:2px solid #2098d4;
- float:left;
- height:36px;
- width:96px;
- color:white;
- font-size:28px;
- font-family:sans-serif;
- border-bottom:1px solid #2098d4;
- line-height: 36px;
- cursor: pointer;
- cursor: hand;
- }
- .smallUnitBox2 {
- z-index: 99;
- background-color:#ed546a;
- float:left;
- height:36px;
- width:96px;
- color:white;
- font-size:28px;
- font-family:sans-serif;
- border-bottom:1px solid #2098d4;
- padding-right:1px;
- line-height: 36px;
- cursor: pointer;
- cursor: hand;
- }
- #chart_div {
- z-index:-1;
- height:100%;
- width:100%;
- }
- input:focus,
- select:focus,
- textarea:focus,
- button:focus {
- outline: none;
- }
- </style>
- </head>
- <body>
- <script>
- var SAT = 0.00000001;
- var BIT = 0.000001;
- var MBIT = 0.001;
- var BTC = 1;
- var currentUnit = BTC;
- function changeColor(div) {
- document.getElementById('satoshiBox').style.background='#29b8ff';
- document.getElementById('bitBox').style.background='#29b8ff';
- document.getElementById('BTCBox').style.background='#29b8ff';
- document.getElementById('mBTCBox').style.background='#29b8ff';
- document.getElementById(div).style.background='#ed546a';
- }
- function satoshiConvert(input) {
- if (currentUnit != SAT) {
- input.value = (convertBTC(input.value) / SAT).toFixed(0);
- currentUnit = SAT;
- changeColor('satoshiBox');
- btcConvert(input);
- }
- }
- function bitConvert(input) {
- if (currentUnit != BIT) {
- input.value = (convertBTC(input.value) / BIT).toFixed(2);
- currentUnit = BIT;
- changeColor('bitBox');
- btcConvert(input);
- }
- }
- function mBTCConvert(input) {
- if (currentUnit != MBIT) {
- input.value = (convertBTC(input.value) / MBIT).toFixed(4);
- currentUnit = MBIT;
- changeColor('mBTCBox');
- btcConvert(input);
- }
- }
- function bitcoinConversion(input) {
- if (currentUnit != BTC) {
- input.value = (convertBTC(input.value) / BTC).toFixed(8);
- currentUnit = BTC;
- changeColor('BTCBox');
- btcConvert(input);
- }
- }
- function convertBTC(value) {
- if (currentUnit == SAT) {
- value = value * SAT;
- return value;
- } else if (currentUnit == BIT) {
- value = value * BIT;
- return value;
- } else if (currentUnit == MBIT) {
- value = value * MBIT;
- return value;
- } else if (currentUnit == BTC) {
- return value;
- }
- }
- function btcConvert(input) {
- if(isNaN(input.value)) {
- document.getElementById('equals').innerHTML = "enter a number";
- }else {
- document.getElementById('equals').innerHTML = "=";
- }
- var price = "<?php echo $bitcoinPrice; ?>";
- var out = convertBTC(input.value) * price;
- var co = document.getElementById('cur');
- cur.value = out.toFixed(2);
- }
- function usdConvert(input) {
- if(isNaN(input.value)) {
- document.getElementById('equals').innerHTML = "enter a number";
- }else {
- document.getElementById('equals').innerHTML = "=";
- }
- var price2 = "<?php echo $bitcoinPrice; ?>";
- var out2 = input.value / (price2 * currentUnit);
- var co2 = document.getElementById('btc');
- if (currentUnit == SAT) {
- var rounding = 0;
- } else if (currentUnit == BIT) {
- var rounding = 2;
- } else if (currentUnit == MBIT) {
- var rounding = 4;
- } else {
- var rounding = 8;
- }
- btc.value = out2.toFixed(rounding);
- }
- google.load('visualization', '1', {packages: ['corechart', 'line']});
- google.setOnLoadCallback(drawAxisTickColors);
- function drawAxisTickColors() {
- var data = new google.visualization.DataTable();
- data.addColumn('number', 'X');
- data.addColumn('number', 'Price');
- data.addRows([
- <?
- $i = 0;
- foreach ($bitcoinPriceArr as $v) {
- echo "[".strval($i+1).", ".$v."]";
- $i++;
- if ($i < count($bitcoinPriceArr)) {
- echo ", ";
- }
- }
- ?>
- ]);
- var options = {
- chartArea: {
- left: 0,
- top: 0,
- right: 0,
- bottom: 0,
- width: "100%",
- height: "100%"
- },
- hAxis: {
- textPosition: 'none',
- baselineColor: 'none',
- gridlines: {
- color: 'none'
- },
- },
- vAxis: {
- textPosition: 'none',
- baselineColor: 'none',
- gridlines: {
- color: 'none'
- }
- },
- colors: ['blue', '#ffffff'],
- legend: 'none'
- };
- var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
- chart.draw(data, options);
- }
- </script>
- <center>
- <div class = "ratesBox">
- <div class = "bitcoin">
- <div class = "rateboxy"><input value = "1" type="text" name = "btc" id="btc" class="rate" onchange="btcConvert(this);" onkeyup ="btcConvert(this);"/></div>
- </div>
- <div class= "unitBox">
- <div class = "smallUnitBox" onclick="satoshiConvert(btc);" id="satoshiBox">sat</div>
- <div class = "smallUnitBox" onclick="bitConvert(btc);" id="bitBox">bit</div>
- <div class = "smallUnitBox" onclick="mBTCConvert(btc);"id="mBTCBox">mBTC</div>
- <div class = "smallUnitBox2" onclick="bitcoinConversion(btc);" id="BTCBox">BTC</div>
- </div>
- <p id = "equals">=</p>
- <div class = "rateboxy"><input value = "<?php echo $bitcoinPrice; ?>"type="text" name="cur" id="cur" class="rate" onchange="usdConvert(this);" onkeyup ="usdConvert(this);"/></div>
- </div>
- </center>
- <div id="chart_div"></div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement