MySQL timestamp - display 3 rows in the last hour

How do I display strings that have a timestamp value in the last hour?

Here is what I have right now, and it shows the last lines, and only 3 lines due to LIMIT.

$query5= mysql_query("SELECT * FROM `made_orders` ORDER by id DESC LIMIT 0,3"); WHILE($datarows5 = mysql_fetch_array($query5)): $name4 = $datarows5['Name']; $phone4 = $datarows5['Phone']; $entree4 = $datarows5['Entree']; $side14 = $datarows5['Side 1']; $side24 = $datarows5['Side 2']; $drink4 = $datarows5['Drink']; $totalcost4 = $datarows5['Total Cost']; $ip4 = $datarows5['Ip']; $id4 = $datarows5['id']; $time4 = $datarows5['timestamp']; echo "<iframe src=\"creatmeal-data.php?id={$id4}\" width=\"430px\" style=\"border:0px\" height=\"350px\"/></iframe>"; endwhile; ?> 

In my code above, every time a string is found, it is an echos iframe. How to edit a query to use the timestamp column to show only the last for an hour.

Thanks in advance for your help!

EDIT: This is what my timestamp column looks like: http://img856.imageshack.us/img856/4135/columnk.png

+6
source share
2 answers

Your current request receives the last three orders, regardless of whether they were created in the last hour.

Use this solution:

 SELECT * FROM made_orders WHERE timestamp >= NOW() - INTERVAL 1 HOUR ORDER BY timestamp DESC LIMIT 3 

In the last hour, this would receive no more than three orders. If there was only one order in the last hour, he would select only one row.

+14
source

SELECT * FROM made_orders ORDER by id WHERE UNIX_TIMESTAMP ( yourTimestampColumn )> UNIX_TIMESTAMP () - 60 * 60

0
source

Source: https://habr.com/ru/post/919988/


All Articles