CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Passing parameters to child form using a button

Print topic Send  topic

Author Message
samelk

Posts: 35
Posted: 04/17/2008, 9:55 AM

Hello,

I have 2 forms, the master and detail. The user enters information into the master form, once it is submitted (and the primary key is generated), I want the child form to open and the primary key of the parent passed to it. Please let me know if this is possible.

Thanks,
Sam
View profile  Send private message
DonP
Posted: 04/17/2008, 10:10 AM

As long as the two forms are on the same page, you can use
LAST_INSERT_ID() to fetch the last auto-generated ID:

$LastEntry = CCDLookUp("LAST_INSERT_ID()", "tablename",
"LAST_INSERT_ID()", $DBconn);

If they are NOT on the same page, then you can do something similar by
saving the result to a session value, then retrieving it on the next page.

Don (DonP)

samelk wrote:
> Hello,
>
> I have 2 forms, the master and detail. The user enters information into the
> master form, once it is submitted (and the primary key is generated), I want the
> child form to open and the primary key of the parent passed to it. Please let
> me know if this is possible.
>
> Thanks,
> Sam
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
samelk

Posts: 35
Posted: 04/17/2008, 10:32 AM

Hi Don,

I guess if I do it this way there is a chance there might me 2 people committing at the same time and might get back the wrong number, right?

How would I do what you said in a query where I can add another value to make sure I get the right PK? How would I access that from the child form?

Thanks,
Sam
View profile  Send private message
DonP
Posted: 04/17/2008, 12:51 PM

The code I gave you would be what you would use in the child form. Just
use the variable wherever you need it. If in a hidden form field or
label, then put in a Before Show event for the field or label and use
the CCS SetValue() function to do so. CCS's Help will show you examples
with details of how to do it but basically it's something like:

// Just in case it gets no value, use global to avoid an ugly error
global $LastEntry;

// Gets that last auto-incremented ID
$LastEntry = CCDLookUp("LAST_INSERT_ID()", "parenttablename",
"LAST_INSERT_ID()", $DBconn);

// Write the value to a form field or to a Label
$ChildGridName->HiddenFieldName->SetValue($LastEntry);

I don't think it matters if there are two submissions at the same time.
I believe that MySQL has a way of coping and will keep them separate.
Maybe someone else can confirm or refute that.

Don (DonP)

samelk wrote:
> Hi Don,
>
> I guess if I do it this way there is a chance there might me 2 people
> committing at the same time and might get back the wrong number, right?
>
> How would I do what you said in a query where I can add another value to make
> sure I get the right PK? How would I access that from the child form?
>
> Thanks,
> Sam
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
samelk

Posts: 35
Posted: 04/17/2008, 7:09 PM

Don,

I appreciate your help. It worked great but I had to use session variables instead of hidden one. Not sure why but I am glad I got it to work.

Thanks again,
Sam
View profile  Send private message
wkempees
Posted: 04/19/2008, 4:06 AM

@Don

Confirmation:
Within the same connection(!),
MySQL will recognize and correctly report back the LAST_INSERT_ID.

If multiple rows are inserted, the last id will be reported back, one would
have to query affected_rows and count back.

Walter

"samelk" <samelk@forum.codecharge> schreef in bericht
news:5480802cf13110@news.codecharge.com...
> Don,
>
> I appreciate your help. It worked great but I had to use session
> variables
> instead of hidden one. Not sure why but I am glad I got it to work.
>
> Thanks again,
> Sam
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>


Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.