Posted data is not populating the grid

QuestionsPosted data is not populating the grid
Aamir asked 11 years ago

Hi Abu,

I have followed this FAQ method
[How to load grid based on $_POST data from other page?]

but it does not work for me.

Here is my code
$formate_from_date = explode('-', $_POST['from_date']);
$_SESSION['formatted_from_date'] = $formate_from_date[2].'-'.$formate_from_date[1].'-'.$formate_from_date[0];

$g->table = "credit_sales WHERE sale_date = '".$_SESSION['formatted_from_date']."'";

I have also tried as assigning the session variable in an other variable e.g.
$formatted_from_date = $_SESSION['formatted_from_date'];
and it does not work too.

It works if I put hard coded value in the Select Command e.g.
$g->table = "credit_sales WHERE sale_date = '2013-07-03'";

I have three posted variables but right now, I am trying to make it work with one.

Best Regards,
Aamir

6 Answers
Abu Ghufran answered 11 years ago

You should use …

if (!empty($_POST['from_date']))
{
$formate_from_date = explode('-', $_POST['from_date']);
$_SESSION['formatted_from_date'] = $formate_from_date[2].'-'.$formate_from_date[1].'-'.$formate_from_date[0];
}

Otherwise, the session variable will reset everytime.

Aamir answered 11 years ago

This has solved the problem. Thank you so much 🙂

Michael Sinne answered 9 years ago

Hi Abu,

I have a similar problem. I'm posting, depending on input, one or more variables, with which I'm doing a select on a database table.

if($_POST['month']) { $date_end = $_POST['month']; } else { $date_end = date('Y-m-d'); }

Then the results (unique invoice numbers) are saved in an array.

$sql_re = "SELECT No FROM MyDatabase.MyTable WHERE (date_format(ServiceEnd, '%Y-%m') = date_format('$date_end', '%Y-%m')) ORDER BY No";
array_push($MyArray, $no);
In the select statement for the parent grid is a where clause with an comparison to the array with the invoice numbers.

$g->select_command = "SELECT DocNo FROM MyDatabase.MySecondTable WHERE No IN('".implode("','",$MyArray)."')";

I'm going the way round with the session, but nothing happens. Still only the first grid call(with default values in the select) is displayed, no matter which dates I changed. When hardcoded the stuff works.
Any idea?

regards

Michael

Abu Ghufran answered 9 years ago

Try following code just before the $date_end setting.

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

if($month) { $date_end = $month; } else { $date_end = date('Y-m-d'); }

Michael Sinne answered 9 years ago

Hi Abu,

no I don't think so.

$sql_re = "SELECT No FROM MyDatabase.MyTable WHERE (date_format(ServiceEnd, '%Y-%m') = date_format('$date_end', '%Y-%m')) ORDER BY No";
array_push($MyArray, $no);

The array with my invoice numbers is properly built after every POST and before the first grid stuff in my script. But the grid only does ONE selection, it ignores the posted data and the updated array.

$g->select_command = "SELECT DocNo FROM MyDatabase.MySecondTable WHERE No IN('".implode("','",$MyArray)."')";

I'm doin the session stuff before the grid select, after I read your note here, but it won't help.

session_start();
$_SESSION['MyArray'] = $MyArray;
$MyArray = $_SESSION["MyArray"];

The grid just doesn't refresh after the post. grmmpff

regards

Michael

Abu Ghufran answered 9 years ago

The session work need to be done for the $_POST variables.

The grid is loaded with 2 server calls.

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

Now, if you want to pass data from external form, it is available for step1. But not there in 2nd ajax call, as it is not posted.
Solution is to put the POST variable in session and use it from session for step2.

Your Answer

1 + 2 =

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?