This topic is locked

time

6/11/2020 8:37:13 AM
PHPRunner General questions
D
dirk author

Hello,
I have a record "time" in the database "online".

It contains the time that the user entered.

Most users do not stay for 2 hours.

therefore I want to delete the record by looking at the time in the record and the current time - 2 hours.
In my listing page I do a refresh every 30 seconds.
Below you see the code in phprunner, but it is not executed
I just want if the stored time is less than the current time - 2 hours, that the rocord will be removed
Who can help me please



Description

Occurs before list page is displayed
Parameters

$xt - template engine object. Use $xt->assign($name, $val) to assign a

value $val to the variable $name

$templatefile - name of the template file being displayed

$pageObject - an object of Page class representing the current page
date_default_timezone_set('Europe/Brussels');

$tijd = strtotime("- 2 hours");
$data = array();

$data["tijd"] < $tijd ;

DB::Delete("online", $data );


Parse error: syntax error, unexpected 'tijd' (T_STRING), expecting ']' in C:\Users\DIRK\Documents\PHPRunnerProjects\GEO_ALLv103\output\include\online_events.php on line 130

Sergey Kornilov admin 6/11/2020

This doesn't look right:

$data["tijd"] < $tijd ;


Should be

$data["tijd"] = $tijd ;
D
dirk author 6/11/2020



This doesn't look right:

$data["tijd"] < $tijd ;


Should be

$data["tijd"] = $tijd ;



This is not what I want, it must be smaller than.
$data = array();

$data["tijd"] < NOW() - INTERVAL 2 HOUR ;

DB::Delete("online", $data );
I also get an error on this :syntax error, unexpected '2' (T_LNUMBER) in line 6

Sergey Kornilov admin 6/11/2020

The following is completely meaningless:

$data["tijd"] < NOW() - INTERVAL 2 HOUR ;


When you update the database you need to specify the actual datetime value. You can not say "I want the value in the database to be less than this".
I guess you are confusing UPDATE and SELECT.

D
dirk author 6/12/2020

I am sorry that it does not work in the normal way, therefore I now have to reconnect the database and then run this:


$mysqli = new mysqli("$host","$username","$password","$database");
// Perform query

$mysqli -> query("DELETE FROM online WHERE datum < (NOW() - INTERVAL 2 HOUR)");


This works perfectly then why does it not work this way ???
$data = array();

$data["tijd"] < NOW() - INTERVAL 2 HOUR ;

DB::Delete("online", $data );

Sergey Kornilov admin 6/12/2020

I see what you saying now. Take another look at the manual:

https://xlinesoft.com/phprunner/docs/db_delete.htm
Under Alternative syntax, you can see your example and this is what you need to use:

DB::Delete("online", "datum < (NOW() - INTERVAL 2 HOUR)" );