This topic is locked

Filter List of records in Lookup Wizard

3/8/2009 08:26:54
PHPRunner General questions
jpedwardspost author

I have 2 tables in a master detail relationship:
Master Table Name: un_tenantgroupnames (This table is the groupname plus other details for a group of tenants)

tg_id auto increment primary key field (integer)

tg_name

lt_signup_id this if the lead tenant signup_id
Detail Table Name: un_signup_details (This table is the tenants in a tenantgroup)

signup_id auto increment primary key field (integer)

signup_name

tg_id foreign key reference to the master table un_tenantgroupnames
So each record in un_signupdetails is linked to a master record in un_tenantgroupnames by the field tg_id.
When I am in inline edit or the edit screen of un_tenantgroupnames I want to populate the lt_signup_id field by picking from a list of the signup_id's (tenants) in this tenantgroup.
So I need to create a lookup from the table un_signupdetails filtered by tg_id.
In Lookup Wizard for field lt_signup_id in table un_tenantgroupnames I have Set the following:

Table: un_signupdetails

Link field: signup_id

Display field: Name

Order by:Name

WHERE: "tg_id =" . $_SESSION["tg_id"]
but I have had no luck. This is what I get when I edit a record on the un_tenantgroupnames table - it occurs where the lt_signup_id field appears.
PHP error happened Technical information Error type256 Error descriptionThis is a general error. It occurs when there is an error in event code or in SQL.
Obviously the sql query is wrong as the where clause has been lost.
Thanks in advance for any suggestions.
JP.

A
alang 3/8/2009

It is normally best to ensure single quotes around the value. ie:
"tg_id ='" . $_SESSION["tg_id"]."'"

jpedwardspost author 3/9/2009

It is normally best to ensure single quotes around the value. ie:

"tg_id ='" . $_SESSION["tg_id"]."'"


Hi Alan,
Thanks for your suggestion. It now runs without any error message but the problem is that it isn't filtering. The problem seems to be that the

$_SESSION["tg_id"] variable either resolves to a NULL value or simply isn't available to commonfunctions.php.
I preceded the line in commonfunctions.php where the 'where clause' is inserted with an

echo statement so I could see what value of tg_id was being used as seen below
Function below copied from commonfunctions.php

------------------------------------------------

// return Lookup Wizard Where expression

function GetLWWhere($field,$table="")

{

global $strTableName;

if(!$table)

$table = $strTableName;

if($table=="un_tenantgroupnames" && $field=="lt_signup_id")
return "tg_id='".$_SESSION["tg_id"]."'";

return "";

}
In the browser the echo statement renders as

[color=#008000]tg_id=''
When I go to edit the record and click the Lookup the list of values that appears is all those records that have a tg_id = '' (which I suppose makes sense).
Any other suggestions much appreciated.
JP.

jpedwardspost author 3/10/2009

After a frustrating battle here is something that may prove useful to others:
In lookup wizard I couldn't get the where clause to work with a $_SESSION expression i.e.
I was trying to filter the lookup to those records that had the same tenantgroup_id (tg_id) as the currently edited record.
I was using the following where expression in the lookup wizard: "tg_id='" . $_SESSION['tg_id'] . "'"
After researching the forum I tried many permutations of the above string but could not get any to work. The $_SESSION['tg_id'] value always seemed to resolve to a NULL value which meant I only saw tenants who didn't belong to any tenantgroup at all.
The solution I found was to use $_REQUEST['editid1'] instead of $_SESSION['tg_id'] so now the where clause in the lookup wizard becomes
"tg_id='" . $_REQUEST['editid1'] . "'"
This picks up the primary key value of the current record as passed as a parameter when you click either the 'edit' or 'inline edit' link on the list page.

e.g. in the following url the value that is passed to $_REQUEST['editid1'] is 326
http://localhost/unacweb/output/un_tenantg...php?editid1=326
and the good news is this $_REQUEST['editid1'] of 326 makes sense in the lookup wizard where clause.
Of course this is only useful when you want to filter the lookup by the primary key field of the record you are editing. If you wanted to filter by some other value in the record you would be back to trying to use $SESSION variables.
I would still very much like to know how to filter a lookup using the $_SESSION variables.
Specifically I would like to know whether the $_SESSION['tg_id'] is something that I should be programmatically assigning before I edit the record (and if so where would I put this code) or is it meant to be something that is automatically set by phprunner once I enter either edit or 'inline edit'?
Hope this helps someone.
JP.

A
andrewpnlp 3/10/2009

Hi,

Not a reply, but a related request (and a warning!)
I also eventually realised that using $REQUEST would cover add, edit, and copy, to filter the lookup list for a given parent ID.
However, when it comes to offering that same lookup on the advanced search, I
don't_ want it filtered. But I can't work out how to have the filter present in the add/edit/copy, but not in the search.
Any ideas? I've found a few places where the WHERE statement is built into the output files, but nowhere that I can edit the statement without having to hack the code every time I issue a new release.
Any and all help will be much appreciated!
Regards,

Andy

A
andrewpnlp 3/10/2009

Ah, a few searches later, and I found it at

http://www.asprunner.com/forums/index.php?...l=lookup++where
Quite a useful post that - some inspiration for other times when you need a field on two pages to act differently!
Regards,

Andy

Hi,

Not a reply, but a related request (and a warning!)
I also eventually realised that using $REQUEST would cover add, edit, and copy, to filter the lookup list for a given parent ID.
However, when it comes to offering that same lookup on the advanced search, I
don't_ want it filtered. But I can't work out how to have the filter present in the add/edit/copy, but not in the search.
Any ideas? I've found a few places where the WHERE statement is built into the output files, but nowhere that I can edit the statement without having to hack the code every time I issue a new release.
Any and all help will be much appreciated!
Regards,

Andy