Jump to content

Problems with my MySQL query


Recommended Posts

Hello!

 

I have a following problem with my MySQL.

 

I have a one table called news, and inside that table I have a two colums called time and subject. Time is for example 14:53 and subject is normal string ..

 

If I would like to make a query which would retrieve last subjects from the last for example 10 minutes I have tried this query:

 

Select subject from news where aika between 'select time(current_timestamp)' and 'select time(now()-interval 10 minute)' but it gives me a zero result set .. I  think I cannot use that kind of "variables" to generate time , but How I am going to make that query then ?

 

Help needed!

 

Petri

 

 

Link to comment
https://forums.phpfreaks.com/topic/144208-problems-with-my-mysql-query/
Share on other sites

  • 4 weeks later...

Are you storing you time as a timestamp or as a string like "14:53"? Also what language are you working in?

 

I am mostly a PHP guy so I would do it like this (not saying this code will work but it will hopefully help point you in the right direction):

$current = time();
$currentLessTen = $current - 600;
$query = 'SELECT subject FROM news WHERE time BETWEEN ' . $currentLessTen . ' AND ' . $current . ' ORDER BY time DESC';

 

"ORDER BY time DESC" assumes you want the results listed from newest to oldest.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.