This topic is locked

add page: before display

1/9/2008 3:31:34 AM
PHPRunner General questions
G
garethp authorDevClub member

Help please - driving myself mad!!!
I have seen several post on similar but just can't make it work.
I have 2 tables
(master) spares with fields order, due

(detail) spares detailwith fields r ecord, order, due, part
linked through order
When the user adds a spares detail (detail) record I would like the field due to be populated with due from the spares (master) table before the screen is displayed - so the user can edit if required. I presume this is an add page: before dispay event but I have not used this before and just can not make it work.
I can do this as a add page:before record added event but this means the user can not edit this field on the add screen which is required.
Many thanks for all your great support - I am so impressed.

J
Jane 1/9/2008

Hi,
here is a sample code of Add page: Before display event:

global $conn,$strTableName;

$str = "select due from spares where order=".$_SESSION[$strTablename."_masterkey1"];

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);
$smarty->assign("value_due",$data["due"]);

G
garethp authorDevClub member 1/9/2008

JUST FANTASTIC - gets better and better!
For other users, I had to make a couple of small chages to make it work as below:

global $conn;

$sql = "select due from spares where sor= '".$_SESSION["spares details_masterkey1"]."'";

$rs = db_query($sql,$conn);

$data = db_fetch_array($rs);
$smarty->assign("value_due",$data["due"]);


Thanks for all your excellent help

G
garethp authorDevClub member 1/10/2008

Jane
One quick question....
I have got this working with one exception.
If I set the field in the add screen to be read only then nothing is displayed - I presume the default in the read only (blank) is overriding the code?
Is there any way for a field to pull in the information and show as read only.
Many thanks

J
Jane 1/11/2008

Hi,
use this code for the readonly fields:

global $conn;

$sql = "select due from spares where sor= '".$_SESSION["spares details_masterkey1"]."'";

$rs = db_query($sql,$conn);

$data = db_fetch_array($rs);
global $readonlyfields;

$readonlyfields["due"] = $data["due"];

G
garethp authorDevClub member 1/11/2008

Thanks so much Jane - PERFECT.