This topic is locked
[SOLVED]

 missing something in php snippet

8/4/2014 9:02:28 AM
PHPRunner General questions
A
Anapolis author

I have an Edit form page where a User selects from one of 5 Events.
I want to show the User the details of the Event they have previously selected, if they already have saved the form with an Event_Id value, such as 1, 2, 3, 4, or 5.
So I must lookup the Events table to get the values of that event and then I want to Display fields from that particular Event IN the Edit form page of a different table.
The only script that works to retrieve those values from the Events table and display them is using the "Before Process" function. In this function I can ask for the values of the current record.
Like this:

global $dal;

$record = $pageObject->getCurrentRecord();
echo $record["event_id"];
global $conn;
if ($record["event_id"]> 0)

$strSQLExists = "select * from wp_pro2014_events where id=" .$record["event_id"]."";
$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

echo $mymessage = $data["event_id"] . "
" .$data["event_location"]. "
" . $data["event_city"] . "
" . $data["start_day"] . "
". $data["start_date"]. "
";

}

else

{

}


But the output is generated above the Header of the page.
The same script as a PHP Snippet fails because it does not recognize the CurrentRecord function.
How can I put the Lookup Fields down into the body of the Edit page form?

A
Anapolis author 8/4/2014

Using the PHP snippet method I cannot find the variable that will pass along the "event_id" value in the current form to be used for the sql lookup of my Events table.
The edit form is for a different table called "Attendees" and it has a field called "event_id" but $data["event_id"] does not work. Nor does $values["event_id"]. Nor does $value["event_id"]. Nor does $oldvalues["event_id"].
None of those ways of specifying the form's current field is passed along when I try to query the Events table in a PHP lookup.
If that would happen then I could put the output exactly where I want it in the body of the Edit form.

A
Anapolis author 8/4/2014

SOLVED!
In my Edit Page "Before Process" function I changed the code to create a Session value --

global $dal;

$record = $pageObject->getCurrentRecord();
echo $record["event_id"];
global $conn;
if ($record["event_id"]> 0)

$strSQLExists = "select * from wp_pro2014_events where id=" .$record["event_id"]."";
$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

$_SESSION["mymessage"] = $data["event_id"] . "
" .$data["event_location"]. "
" . $data["event_city"] . "
" . $data["start_day"] . "
". $data["start_date"]. "
";

}

else

{

}


Then I took the

$_SESSION["mymessage"] and put it into my PHP Code snippet in the Edit page form where I wanted it...
echo $_SESSION["mymessage"];
and I get a Display of the User's current Event choice with User friendly details of Date, location, city, etc.
SOLVED!