It’s a weird situation! I can pass fixed string value to $g->select_command, but cannot do the same with substr function (which return “string” by default). What I’m doing wrong?
Here is the code working fine:
$from_date=”2021/05/10″;
$to_date=”2021/05/10″;
$g->table=”survey”;
$g->select_command=”SELECT * FROM $g->table WHERE timestamp >= ‘$from_date 00:00:00’ AND timestamp select_command=”SELECT * FROM $g->table WHERE timestamp >= ‘$from_date 00:00:00’ AND timestamp select_command is one and the same in both situations. I’ve try also with different style of query setup:
$g->select_command=”SELECT * FROM $g->table WHERE timestamp >= ‘” . $from_date . ” 00:00:00’ AND timestamp = ‘ 00:00:00’ AND timestamp <= ' 23:59:59' ORDER BY `timestamp` DESC LIMIT 20 OFFSET 0
Something messed up with editor, sorry, posting for the first time here, I’ll try to explain again.
Here is the code working fine:
$from_date=”2021/05/10″;
$to_date=”2021/05/10″;
$g->table=”survey”;
$g->select_command="SELECT * FROM $g->table WHERE timestamp >= '$from_date 00:00:00' AND timestamp <= '$to_date 23:59:59'";
Here is the code not working, using PHP substr function (‘daterange’ = ‘2021/05/10 – 2021/05/10’):
$from_date=substr('daterange',0,10);
$to_date=substr('daterange',13,10);
$g->select_command="SELECT * FROM $g->table WHERE timestamp >= '$from_date 00:00:00' AND timestamp <= '$to_date 23:59:59'";
You can see $g->select command is one and the same in both situations. I’ve try also with different style of query setup, like this
$g->select_command="SELECT * FROM $g->table WHERE timestamp >= '" . $from_date . " 00:00:00' AND timestamp <= '" . $to_date . " 23:59:59'"
… but with the same result.
SQL debug query shows empty $from_date and $to_date strings:
SELECT * FROM survey WHERE timestamp >= ' 00:00:00' AND timestamp <= ' 23:59:59' ORDER BY `timestamp` DESC LIMIT 20 OFFSET 0
Hello,
Apologies for the delay. If i understand it correctly, you are perhaps, reading a postback variable so you will need to persist it in session.