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

Context: I’m running a python script that is scrapping 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?

Not being able to fetch the latest data added from MySQL with 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); 

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

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 = => ({ time: datum.Date, open: datum.Open, high: datum.High, low: datum.Low, close: datum.Close}));


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Changing from let to var on javascript has solved the issue which makes sense as this was mainly a scoping issue to retrieve the data from the objects (What’s the difference between using “let” and “var”?)

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x