mysql - Do math inside a SQL statement? -


i'm trying make can select values below 601 (slightly 10 minutes). take time() , subtract field time. don't understand why isn't working. can explain or sql not have ability. don't error, though gives data doesn't make sense.

$pdo->query("select * `online` '".time()."'-`time` > 601"); 

it doesn't seem working.

database

database

sample data

id = 1

uid = 1

time = 1376252614 (to honest, don't know why text. haven't had issue before though, that's why assume it's not problem)

if you're working in mysql , time column datetime or timestamp data type, try query.

where `time` >= now() - interval 601 second 

if time column integer containing unix-style timestamp (or text string showing integer), try this.

where `time` >= unix_timestamp() - 601 

this way of structuring query allows mysql exploit index on time column. but, if timestamp's text string index work little strangely.

notice time suboptimal choice column name because it's mysql reserved word. have diligent enclose in backticks time, or you'll bizarre errors.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -