Help on Lookup_Selecting

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
almaqdad
User
Posts: 20

Help on Lookup_Selecting

Post by almaqdad »

Hello;

I am a new user with PHPMaker. I am working on a project, that I need to filter lookup field based on a value of Sheet_ID. I have tried to pull a value using $this->Sheet_ID->CurrentValue. but it did not worked . plz see the below code.

// Lookup Selecting event
function Lookup_Selecting($fld, &$filter) {
if ($fld->FldName == "Teacher_Name")

	$Get_Sheet_ID=$this->Sheet_ID->CurrentValue; // Get Value from fld!!! BUT DOES NOT WORK !!!

	$Sheet_Hospital = ew_ExecuteScalar("SELECT `Sheet_Hospital` FROM `sheet_db` WHERE `Sheet_ID` = $Get_Sheet_ID");

	ew_AddFilter($filter, "Hospital = '$Sheet_Hospital'"); 

}

Please help me.

Thank you so much


scs
User
Posts: 694

Post by scs »

almaqdad wrote:
$Sheet_Hospital = ew_ExecuteScalar("SELECT Sheet_Hospital FROM sheet_db WHERE
Sheet_ID = $Get_Sheet_ID");

ew_AddFilter($filter, "Hospital = '$Sheet_Hospital'");

// if then $Sheet_ID is string
$Sheet_Hospital = ew_ExecuteScalar("SELECT Sheet_Hospital FROM sheet_db WHERE Sheet_ID = '". $Get_Sheet_ID ."'");
ew_AddFilter($filter, "Hospital = '". $Sheet_Hospital ."'");

// if then $Sheet_ID is numric
$Sheet_Hospital = ew_ExecuteScalar("SELECT Sheet_Hospital FROM sheet_db WHERE Sheet_ID = ". $Get_Sheet_ID);
ew_AddFilter($filter, "Hospital = ". $Sheet_Hospital);


almaqdad
User
Posts: 20

Post by almaqdad »

Hello dear scs,

Yes there was a wrong in syntax. I fixed it but the issue still exist. I find out that the value $this->Sheet_ID->CurrentValue is not available in Lookup_Selecting function, so I have pulled the value in function Row_Rendered() and store it in $_SESSION['curr_sess']

// Row Rendered event
function Row_Rendered() {
$Get_Sheet_ID=$this->Sheet_ID->CurrentValue;
$Sheet_Hospital = ew_ExecuteScalar("SELECT Sheet_Hospital FROM sheet_db WHERE Sheet_ID = ". $Get_Sheet_ID);
$_SESSION['curr_sess'] = "$Sheet_Hospital";
}

Then I called the $_SESSION['curr_sess'] in function Lookup_Selecting

// Lookup Selecting event
function Lookup_Selecting($fld, &$filter) {
if ($fld->FldName == "Teacher_Name")
ew_AddFilter($filter, "Hospital = '". $_SESSION['curr_sess'] ."'");
}

The Lookup field filter worked fine in Single Add/Edit Page ONLY. However, in Grid ADD and in inline Add does not work. I enable the debug mode . see the error below :

(mysqlt): SELECT Sheet_Hospital FROM sheet_db WHERE Sheet_ID =
Error (1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

(mysqlt): SELECT Sheet_Hospital FROM sheet_db WHERE Sheet_ID =
Error (1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

(mysqlt): SELECT Sheet_Hospital FROM sheet_db WHERE Sheet_ID =
Error (1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

(mysqlt): SELECT Sheet_Hospital FROM sheet_db WHERE Sheet_ID =
Error (1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

(mysqlt): SELECT Sheet_Hospital FROM sheet_db WHERE Sheet_ID =
Error (1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

(mysqlt): SELECT Sheet_Hospital FROM sheet_db WHERE Sheet_ID =
Error (1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

It seem again, the value of $_SESSION['curr_sess'] is getting lost in Grid ADD and in inline Add !!!?

Any ideas
Thank you again for your help


danielc
User
Posts: 1601

Post by danielc »

There is no value for your session value during gridadd and inline add which cause the error message.

The possible solution may be to use Dynamic Selection List. You can set parent filter for your field. See Field Setup in help file and Tutorial - Dynamic Selection List.


almaqdad
User
Posts: 20

Post by almaqdad »

Thank you all for reply.

I have figured out that Sheet_ID Field option was not set as Show field in list page. that's why the value was not captured.


Post Reply