This topic is locked

Show master table data in add, edit or view page.

7/11/2012 7:47:12 AM
PHPRunner General questions
R
renelasser author

I'm having trouble getting the Show data from master table in add, edit or view page to work.
My master table is:

owners

Key field is:

owner_ID

And I wish to show data from field

currency

in a add new page which adds data to table

DealerListings.

In dealer listings the foreign key is

owner_ID
Here is the snipped code I'm using as provided in the help section.
global $dal, $strTableName;

echo "Master Info:
";

if ($_SESSION[$strTableName."_masterkey1"])

{

$tblMaster = $dal->Table("owners");

$rs = $tblMaster->Query("owner_ID=".$_SESSION[$strTableName."_masterkey1"],"");

if ($data = db_fetch_array($rs))

{

echo "Currency: ".$data["currency"]."
";

echo "Phone: ".$data["phone1"]."
";

}

}
The problem is the data from the field currency and phone1 does not show.

There is no error, I just don't get the desired result.

Only the words Master info: show where I have placed the snippet but not the data from the resource.
I placed the sippet in a add new page.
I hope someone can give me some hints with this. I have tried everything and am at my wits end.
Many thanks to the kind person who can help me over this hurdle.
Rene

Sergey Kornilov admin 7/19/2012

A number of things can go wrong here. As a first step you need to make sure all table and field names are correct (case-sensitive). Another thing - make sure that $_SESSION[$strTableName."_masterkey1"] variable is populated.
The next step - make sure your query returns data. Add the following statement there, copy the SQL and execute it manually against your database to see if any data is there and there are no errors:

echo "select * from owners where owner_ID=".$_SESSION[$strTableName."_masterkey1"];