CodeCharge Studio
search Register Login  

Web Reporting

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

YesSoftware Forums -> CodeCharge Studio -> PHP

 Retrieving the actual data

Print topic Send  topic

Author Message
Amdja
Posted: 03/31/2005, 8:40 AM


Hi,

I have a problem with getting the data i've just inserted.

The point is, I insert a record in a table, i don't write the primary key due is generated by itself. But i need the value of the primary key.

My current solution is to do a select inmediatly after inserting the record and to get the max(primary key field) of the table. It's not a pretty solution... It should be a rigth solution, I guess.

Thanks
zeuch


Posts: 25
Posted: 03/31/2005, 4:28 PM

Hi,
I use this solution too. To minimize the chances of errors, you can select the primary key whit a where clause with somes fileds you can get by post parameter.

If anybody have another solution please post here.

Regards,
Matheus
_________________
Matheus Zeuch
View profile  Send private message
dptroutt
Posted: 03/31/2005, 7:14 PM

I have what sounds like an identical/similar situation.

I've created a page with an event registration form based on a single table. The primary key is an autonumbered column.

After the data is entered, the user is forwarded to a "confirmation" page which displays their selections along with computed $ amounts.

If I do nothing, it simply displays the information from the first record in the database table.

I've tried adding CustomCode for an After Insert Event, but I had to adapt a sample and I'm getting a Fatal error: Call to a member function GetValue() on a non-object in C:\Program Files\Apache Group\Apache2\htdocs\ACPreg_events.php on line 22

here is the entire Custom Code - Line 22 begins "$LastId = web_ac_prereg ......"

Any help will be appreciated.

Thanks.
dptroutt
Posted: 03/31/2005, 7:16 PM

Sorry, here's the code

//Custom Code @91-91E09946
// -------------------------
global $web_ac_prereg;
global $DBweb_chea;
global $Redirect;
if(!CCGetFromGet("web_transid", 0)) {
$LastID = $web_ac_prereg->web_transid->GetValue();
if (strpos($Redirect,"?") == false ) {
$Redirect = $Redirect."?NewTrans=Yes&web_transid=".$LastID;
} else if (substr($Redirect,-1) == "?" ) {
$Redirect = $Redirect."NewTrans=Yes&web_transid=".$LastID;
} else {
$Redirect = $Redirect."&NewTrans=Yes&web_transid=".$LastID;
}
}
// Write your own code here.
// -------------------------
//End Custom Code

//Close web_ac_prereg_AfterInsert @4-0155C664
return $web_ac_prereg_AfterInsert;
Nicole

Posts: 586
Posted: 04/01/2005, 1:25 AM

Hello,
If you’re working with MySQL retrieve new autoincrement primary key value in After Execute Insert event using code:
  
global $form_name;   
$LastID = mysql_insert_id($form_name->ds->Link_ID);   
Keep in mind that you need to use real form name in your code.
The other way is to retrieve max primary key using CCDLookUp() function as it is done in Multi Step Registration example (step 1)
http://examples.codecharge.com/ExamplePack/MultiStepReg...trationGrid.php



_________________
Regards,
Nicole
View profile  Send private message
dptroutt
Posted: 04/01/2005, 10:06 AM

Quote Nicole:
Hello,
If you’re working with MySQL retrieve new autoincrement primary key value in After Execute Insert event using code:
  
global $form_name;   
$LastID = mysql_insert_id($form_name->ds->Link_ID);   
Keep in mind that you need to use real form name in your code.
The other way is to retrieve max primary key using CCDLookUp() function as it is done in Multi Step Registration example (step 1)
http://examples.codecharge.com/ExamplePack/MultiStepReg...trationGrid.php


Nicole;

Thank you for your response. I am using RBase and a special versions of CCS made to work with RBase through their ODBC driver, Oterro.

I will try your code.

However, I looked here http://examples.codecharge.com/ExamplePack/MultiStepReg...ration_desc.php

and could find no reference to CCDLookUp; just this

"Programming Notes
The Record form’s After Insert event is used to retrieve the last inserted key (user_id) after the user record is created. The key is then passed to the next page as a URL parameter."

The After Insert event is what I've been trying to use.

Thanks.

Nicole

Posts: 586
Posted: 04/02/2005, 6:02 AM

I meant that you need to refer to generated MultiStepRegistration1_events.php file code and check the code in After Insert event. It contains CCDLookUp().
_________________
Regards,
Nicole
View profile  Send private message

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.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


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