Grid Doesnt show results when the SQL is created with PHP variables

QuestionsGrid Doesnt show results when the SQL is created with PHP variables
Peter Perera asked 10 years ago

Hi All,

Grid Doesn't show results when the SQL is created with PHP variables. I'm using the free version of jqgrid.

But when I hardcode the sql in php code, it works.

Following is the code

$g->select_command = "SELECT p.id,c.compName,p.chk_no,p.payAmt,b.bcode,b.bankbranch FROM tblpayments p, tblcustomers c, tblbank_list b WHERE p.cusId=c.id AND p.bankAcc=b.id AND p.logedDate BETWEEN $ff AND $tt;

I've tried with
"… p.logedDate BETWEEN ".$ff." AND ".$tt;
"… p.logedDate BETWEEN '".$ff."' AND '".$tt."'";

When echo this statement, it gives something like this.

SELECT p.id,c.compName,p.chk_no,p.payAmt,b.bcode,b.bankbranch FROM tblpayments p, tblcustomers c, tblbank_list b WHERE p.cusId=c.id AND p.bankAcc=b.id AND p.logedDate BETWEEN 1391299200 AND 1405814399

This has many records.

Please help me to solve this.

4 Answers
Abu Ghufran answered 10 years ago

The grid is loaded with 2 server calls.

1) load the columns of grid.
2) do an ajax call, to load data of grid.

if you want to use other variables, they is available for step1. But not there in 2nd ajax call, as it is not posted.
Solution is to put those variable in session and use it from session for step2.

e.g.

if (!empty($ff))
{
$_SESSION["ff"] = $ff;
}
$ff = $_SESSION["ff"];

Abu Ghufran answered 10 years ago

Hi Bruce,

You can email me the code for review at [email protected]

Bruce Rick answered 8 years ago

I'm doing this in mine but its still only working on the first call. Not sure if I'm doing something wrong or what. I echo out the sql command to see it and I can see it gets the variable the first call but then second one fails and doesn't make it. It makes no sense that the Session variable isn't even being picked up on the second attempt.

Bruce Rick answered 8 years ago

Forget that one. I had to move my if statement directly before the SQL command and then it started working. No idea why but something must have been causing problems in my code.

Your Answer

0 + 6 =

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?