Pass string value to $g->select_command from PHP function substr

QuestionsPass string value to $g->select_command from PHP function substr
Vladimir Gerdjikov asked 3 years ago

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

2 Answers
Vladimir Gerdjikov answered 3 years ago

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

Abu Ghufran Staff answered 3 years ago

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.

Refer: Misc FAQs – Grid 4 PHP Framework Docs (gridphp.com)

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Your Answer

19 + 17 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?