Tuesday, 28 August 2018

Entering data from the mysql table using php microtime does not work correctly

I am displaying a long list of sales details from a table in mysql. The problem is I am being able to fetch data only for a month. As soon as the month changes it doesnt display anything. For ex: data being displayed from 1/05/2015 to 30/05/2015 but from 1/06/2015 it does not display anything.

I add the timestamp values on each sale in the database using the following code:
$time = round(microtime(true)*1000);

Rest of the code is here:
<?php
include 'connect.php';
$timestamp = "";
$return = array();
$response = "";
$sql = "SELECT * FROM receipts ORDER BY timestamp DESC LIMIT 1";
$result1 = mysqli_query($db, $sql);
if($details = mysqli_fetch_array($result1)){
    $timestamp = $details['timestamp'];
}

$sql = "SELECT * FROM sales WHERE timestamp>'$timestamp' ORDER BY date ASC";
$result = mysqli_query($db, $sql);

echo "<table class=table1>";
while($fetch_options=mysqli_fetch_array($result)){
    $memo=$fetch_options['memo'];
    $product=$fetch_options['pid'];
    $qty=$fetch_options['qty'];
    $amount=$fetch_options['amt'];

    echo "<tr>";
    echo "<td align=center>$memo</td>
             <td align=center>$product</td>
             <td align=center>$qty</td>
             <td align=center>$amount</td>";
    echo "</tr>";
}
echo "</table>";
?>

I feel this problem is something to do with the timestamp values. Thanks in advance.

i would commented but it still don'T have enough rep to do that.
Something tells me you should use time()instead of microtime()
time() will return the time in seconds as an INT. microtime() will give you time in microseconds as STRING or as FLOAT by using true as a first parameter => microtime(true)
As i can see you are multiplying microtime() by 1000. That will give you the same as time().
Try using time() instead of round(microtime()*1000).

0 comments:

Post a Comment