This topic is locked
[SOLVED]

 After Table Initialized

11/16/2012 11:37:41 AM
PHPRunner General questions
S
StefanoF author

Hi.

I'm using PHPRunner 6.2 and I'm new to it.
My need is to apply a filter, on different page list, depending on the username.
So I've inserted the following code in the "After TAble Initialized" event.
$filtro = "UserName ='".$_SESSION[UserName]."' and TableName ='".$strTableName."'";

$tblFilt = $dal->Table("coge_trs_php_TableFilter");

$rs = $tblFilt->Query($filtro);

$data = db_fetch_array($rs);
if ($data['UserFilter'] != '')

$query->addWhere($data['UserFilter']);
Inside "coge_trs_php_TableFilter" there's only 1 record, therefore there's only 1 filter to be applied on List page "TABLE_1".
The first test was done on the "TABLE_1" page list, linked to a child table ("TABLE_2"), and worked perfectly.

As the "TABLE_2" has is own page list, I've copied the same code in the "After TAble Initialized" event.

The next test on "TABLE_1" list page, did not work.

The problem seems to be on "TABLE_1" when the php tries to count the childnumber on TABLE_2.

In the "After Table Initialized" event on "TABLE_2" the variable $strTableName is set with "TABLE_1" instead of "TABLE_2" and obviously the filter for "TABLE_1" doesn't work for "TABLE_2".
Now the question is, how can I get the right table name ? I've tried with $_SESSION variable but, most probably due to my inexperience, with no success.
Thanks.
Stefano

C
cgphp 11/17/2012

If you want to filter the records on the List page, add the filter code to the "Before SQL query" event. More info: http://xlinesoft.com/phprunner/docs/before_sql_query.htm http://xlinesoft.com/phprunner/docs/modify_sql_query_on_the_fly.htm

S
StefanoF author 11/19/2012



If you want to filter the records on the List page, add the filter code to the "Before SQL query" event. More info: http://xlinesoft.com/phprunner/docs/before_sql_query.htm http://xlinesoft.com/phprunner/docs/modify_sql_query_on_the_fly.htm


Thank you Cristian. Besides the suggested solution, is there a way to get the right table name inside the "After Table Initialized" event ?
Stefano

C
cgphp 11/19/2012
global $strTableName;
$filtro = "UserName ='".$_SESSION[UserName]."' and TableName = '".$strTableName."'";

...

...
...
S
StefanoF author 11/19/2012


global $strTableName;
$filtro = "UserName ='".$_SESSION[UserName]."' and TableName = '".$strTableName."'";

...

...
...



Cristian, that's the code I wrote in both, TABLE_1 and TABLE_2, "After Table Initialized" event. The problem is on the TABLE_2 childnumber inside TABLE_1 list page. For each TABLE_1's row, when childnumber's query is executed, the variable $strTableName contains the master tabel name (TABLE_1) instead of details table name (TABLE_2) and the childnumber's query crashes.

I was trying this solution, instead of the one you suggested in your first post, so that the childnumber displayed on the list page would have been affected by the same filter.

For example, record_1 of TABLE_1, already filtered, has 10 children on TABLE_2 but, due to filter, only 6 of them should be displayed. With the solution I was trying to apply, the childnumber displayed would have been 6.
Thanks a lot.
Stefano