Jump to content

Cannot get the correct data in my html table(live price) using php and java, it giving me the wrong info when I run the index.php file


Recommended Posts

Good day.

I am new to php, did learn quit a few things with php, but now I am stuck. (don't hurt the newbie) 

1.  in phpmysql I have a table with one of the columns (LIVE) in it that I want to show a live price in.

     At the moment I the column is set as varchar(30) do not know if this is correct.

     In my html table I want to add 3 or more if/else in, so when I update my html it must show 0.03234523 (depending on the price) I do not want all the rows to show this          information

    I am getting the info from a js file, but cannot get it to work. (I did add the script in so it see my sss.js file.

Here is the full script of javascript (it is at the moment just for one, will add the other two later when we can fix this), and the php script from my php file.

What am I dong wrong and how can I fixed it.

let ws_binance = new WebSocket('wss://stream.binance.com:9443/ws');
let html_element_binance = document.getElementById('show_price_binance');
let last_price_binance = null;
ws_binance.onopen = function () {
    ws_binance.send(JSON.stringify ({
        'method': 'SUBSCRIBE',
        'params': ['shibusdt@trade'],
        'id': 1
    }))
};
ws_binance.onmessage = function (event) {
    let current_price_binance = JSON.parse(event.data);
    let price_binance = parseFloat(current_price_binance.p).toFixed(8);
    html_element_binance.innerText = price_binance;

    if ((price_binance < last_price_binance) && (isNaN(price_binance) == false)) {
        html_element_binance.innerText = '↓' + price_binance;
        html_element_binance.style.color = 'red';
    } else if ((price_binance > last_price_binance) && (isNaN(price_binance) == false)) {
        html_element_binance.innerText = '↑' + price_binance;
        html_element_binance.style.color = 'lime';
    } else if ((price_binance == last_price_binance) && (isNaN(price_binance) == false)) {
        html_element_binance.innerText = price_binance;
        html_element_binance.style.color = 'purple';
    }
    last_price_binance = price_binance;
};
<td>
  <?php 
$checkSqlRow["CCOINGECKO_LIVE"] = strtolower($checkSqlRow["COINGECKO_LIVE"]);  
if($checkSqlRow["COINGECKO_LIVE"] == 'trx') { echo "id='show_price_binance'";  }
            
?>
</td>

 

"in phpmysql I have a table ..."

Google Chrome is an Application that lets you work with Web Pages (that run inside a Web Server process like Apache). 
PHPMyAdmin is an Application that lets you work with Databases (that run inside the MySQL DBMS process). 

 

"... a table with one of the columns... I want to show a live price in ... At the moment I the column is set as varchar(30) do not know if this is correct."

In short - It's not. 

Always store your data values in columns of the correct Data Type

You will want to do numerical things with these values (like adding them up) so you want then in a numerical column type. 
If you don't do this then: 

  1. your queries will run more slowly because the database has to convert the character value into a number each and every time you use it, and
  2. You run the risk of losing numerical accuracy (e.g. rounding errors) during those "implicit" Type Conversions. 

 

"In my html table I want to add 3 or more if/else in, so when I update my html it must show 0.03234523 (depending on the price) I do not want all the rows to show this information"

If you only want to hold values in your table for particular rows, then you need to consider making the column NULLable so that you can "leave out" that particular field in any given row. 

If you only want to suppress the value visually in the HTML (which, if I'm honest, seems a bit odd to me, given that this is the price of something) then you'll need to keep track of (or go and find) the price value from the previous row and, only output the current value if it is different from that previous one. 

Regards, 
   Phill  W.

 

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.