hendrikbez Posted June 30, 2022 Share Posted June 30, 2022 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> Quote Link to comment https://forums.phpfreaks.com/topic/314978-cannot-get-the-correct-data-in-my-html-tablelive-price-using-php-and-java-it-giving-me-the-wrong-info-when-i-run-the-indexphp-file/ Share on other sites More sharing options...
Phi11W Posted June 30, 2022 Share Posted June 30, 2022 "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: 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 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. Quote Link to comment https://forums.phpfreaks.com/topic/314978-cannot-get-the-correct-data-in-my-html-tablelive-price-using-php-and-java-it-giving-me-the-wrong-info-when-i-run-the-indexphp-file/#findComment-1597751 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.