sql NOW() in Server-Side Processing
sql NOW() in Server-Side Processing
Trying to switch from a working but slow client-side table to server-side, using ssp.class.php.
In my sql query I've previously used 'NOW()-lastseen as age'. I've tried including "Now()-lastseen" as a column which fails.
Is there any way to achieve this with the stock ssp.class.php? I'm thinking what bites me is that it ends up using it as `NOW()-lastseen` which isn't valid. I guess I could alter ssp.class.php and make it work, is there another way?
j
This question has an accepted answers - jump to answer
Answers
I would suggest altering it. I made a lot of changes to mine, but one quick and simple alteration you can make is to make your
FROM
a subquery. So instead of$table = 'my_table'
you can do something like:Another option is to perform the calculation in PHP. Great the time stamp and then modify the data with the calculation before sending it back to the client. Not as efficient, but likely efficient enough since it will only be doing 10 or so records at a time rather than thousands.
Beyond that, likely you would need to modify the SSP class as it is really just a simple demo script and not designed to handle cases such as functions and expressions. Probably not a hard modification, but not something I've tried I must admit.
Allan
I really liked the subquery suggestion. Unfortunately, ssp.class.php uses the explicit 'databasename.tablename' syntax and errors out if I try it.
I ended up just removing the backticks from ssp.class.php. I had one field that required them (named 'range' colliding with mysql) and I included the backticks in the db field spec in the php, then turned around and just renamed the field in the DB as 'distance'. (added a couple hours updating other things that touch this DB, but something I'd meant to do some time ago anyway)
Thanks for suggestions.
j