This topic is locked

Records from another table displayed on Edit page

10/5/2007 4:02:49 PM
PHPRunner General questions
hfg author

I saw another post that gave me this idea and I'm hoping it is possible using the events...
2 Tables - Customer (Key - ID) and a child table called Notes (ID_Cust is the forign key)(Other fields are Note_ID (key), Note, Date and Name)
Is there a way when the user clicks on Edit for the Customer table that all of the related records from the Notes table can be displayed. This would only have to be in text (i.e. read only).
It might look like this:
Customer Name:

Addrress:

City:
(Save button)
Related Notes:

10/5 Called Customer John

10/4 Customer call and said hi Sam
This would save my sales people a couple steps and put all of the info right in front of them.

J
Jane 10/6/2007

Hi,
you can do it using EditOnLoad event on the Events tab for the Customers table.

You can see sample code for this event in the PHPRunner livedemo 3:

http://livedemo.asprunner.net/phprunner/li...p?editid1=10248
Here is a sample code:

global $strWhereClause;

global $conn;
$rs = db_query("select ID from Customers where ".$strWhereClause, $conn);

$data = db_fetch_numarray($rs);

$CustomerID = $data[0];

//

$rs1 = db_query("select Note, Date, Name from Notes where ID_Cust=".$CustomerID."",$conn);
$message.= "<TABLE cellSpacing=0 cellPadding=5 width=\"100%\"";

$message.= "align=center border=0><TBODY>";

$message.= "<tr><td colspan=3 class=downedit2>";

$message.= "<font color=black>Related Notes:</font>";
while ($data1 = db_fetch_array($rs1))

{

$Note = $data1["Note"];

$Date = $data1["Date"];

$Name = $data1["Name"];
$message.= "<tr><td>".$Note."</td>";

$message.= "<td >".$Date."</td>";

$message.= "<td >".$Name."</td></tr>";

}

$message.= "</TBODY></TABLE>";
echo $message;


You can download all live demos here:

http://www.xlinesoft.com/phprunner/livedemo4.htm

hfg author 10/8/2007

1st one more question, is there a way to change the sort order to desc (newest to oldest)?
A note for anyone else trying this, I had to add "global $message;"
<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=22026&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' /> Thank you, it works great!

J
Jane 10/8/2007

Hi,
just add order by clause to your SQL query:

...

$rs1 = db_query("select Note, Date, Name from Notes where ID_Cust=".$CustomerID."order by Date Desc",$conn);

...