This topic is locked

Masterkey value

2/24/2011 12:42:25 PM
PHPRunner General questions
bbarker author

I HAVE REWRITEN MY QUESTION:

-----------------------------
I have a database with 30,000 records... I show them in DESC order so that the most recently added record shows up first.

When I log in and go directly to VENDOR LIST, the newest record shows up (example: VendorID = 30000).
In a related table I store all of the past years that they have done business with us. (Year = nnnn).
When I view the Vendor, I want to search for Max(Year) to find the last time (year) that they did business with us.) I use the BEFORE SHOW LIST Event[size="4"][/size] to do this.
My query looks like this:

$query = SELECT MAX(Year) FROM mastertable WHERE VendorID = ".$_SESSION["mastertable"."_masterkey1"];
But this doesn't work. There is no masterkey1.
My question is:

[size="5"]"What record-variable do I use to identify the first record that shows up (VendorID=30000) so that I can pull other data from their tables?"[/size]

.

.

.

.

.

.
=======PREVIOUS VERSION OF THIS QUESTION========================

I tried to use

print_r ($_SESSION["mastertable"."_masterkey1"]);

in Before List Page is Displayed but it comes back "blank".
The detail table works okay.

print_r ($_SESSION["detailtable"."_masterkey1"]);

So, I've finally realized that the MASTERKEY1 doesn't get assigned until a detail table is displayed. Right?
What can I use on the very first displayed record as that record's session identity? The VendorID is the record's key field.
SAMPLE BAD QUERY



$query = "SELECT MAX(Year) FROM mastertable WHERE VendorID = ". $_SESSION["mastertable"."_masterkey1"];
Sergey Kornilov admin 2/24/2011

If you link two tables as master-details you proceed to details table after selecting a master record - $_SESSION["mastertable"."_masterkey1"] is a proper way to retrieve master key value. Just make sure you use the real table name instead "mastertable".
If this doesn't help post your application to Demo Account and open a ticket at http://support.xlinesoft.com sending your Demo Account URL. 'Demo Account' button can be found on the last screen in the program.

bbarker author 2/24/2011

Thanks Sergey.
I will probably end up sending you a copy over the weekend.

Can I try one more time first?
I need a query to work when the MASTER table displays for the FIRST TIME.
I want to display the MAX value from a second (tblstalls) table.

But it's not working during the BEFORE SHOW LIST Event.
$query = "SELECT MAX(Year) FROM tblstalls WHERE VendorID = ". $_SESSION["tblstalls"."_masterkey1"];

$result = mysql_query($query) or die("query failed with this error: ".mysql_error());

$data=db_fetch_array($result);

echo "<br/>MAX Year: ".$data['MAX(Year)'];
EDIT: I can see that "WHERE VendorID =" is wrong.