简体   繁体   中英

Not being able to fetch the latest data added from MySQL with PHP

Context : I'm running a python script that is scraping stock data and sending this data to a MySQL database and that is working just fine. Now, I'm displaying the data in a candlestick chart, however, I can only display the data from the main batch of data (basically the data I pushed into the database at once, all on the same day, 7th October 2021). The script is now running daily and saving the daily stock prices as usual, but I can't retrieve the latest data added and pass it onto my chart (it uses an array of objects). As you can see from the image, it shows that I have 2840 objects with their correspondent properties, but it is not fetching the latest updated stock price (Friday, 8th October 2021). I can see in my MySQL database that the prices are all there (including the most recently added ones from Friday), but I can't seem to pass it to the chart nor see that value on my array of objects. Any help?

数据

PHP:

if (isset($_POST['submit'])) {
    $ticker = $_POST['ticker'];
    $intval = $_POST['intval'];

    $stmt = $conn->prepare("SELECT Date, Open, High, Low, Close FROM symbolsv2 WHERE ticker=? AND `intval`=? AND Open AND High AND Low AND Close IS NOT NULL ORDER BY Date");
    $stmt->bind_param("ss", $ticker, $intval); 
    $stmt->execute();

    $result = $stmt->get_result();
    while ($data = $result->fetch_assoc()) {
      $data_array[] = $data;
    } 
    $stmt->close();
}
$conn->close();

Javascript (I'm collecting the data from the PHP array, saving it onto a javascript variable with the desired output that the candlestick chart requires)

    let data = <?php echo json_encode($data_array) ?>;
    
    let data_new = data.map(datum => ({ time: datum.Date, open: datum.Open, high: datum.High, low: datum.Low, close: datum.Close}));

在 javascript 上从let更改为var解决了这个问题,这很有意义,因为这主要是从对象中检索数据的范围问题( 使用“let”和“var”有什么区别?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM