> -----Original Message-----
> From: Bob O [mailto:[email protected]]
> Sent: 27 February 2009 20:31
> To: [email protected]
> Subject: Re: [fw-general] lastInsertId()
> 
> 
> FYI..all 3 tables have auto_incrementing id fields that are PK's
> and when all parts pertaining my problem
> 
> i am able to submit all of the other information correctly..
> 
> 
> 
> Bob O wrote:
> >
> > Im having a heck of a time with this one..I have searched high and low,
> > and what has seemed to be a remedy isnt working for me..
> >
> > any help would be great
> >
> > I have 1 form and 3 tables that i submit to with 1 post.
> > These tables are joined by ids
> >

[snip]

> -----
> Bob Hanson
> Web Developer
> SLC, UT

To follow up on Jason's post here is some code I use here to insert into a
master table (contact), do a lookup on a lookup table (contact_category) and
then insert to the relation table (FK, contact_area)

HTH,


                        // Insert the main contact information into the
database;
                        $contact = new CustomerContact();
                        $data = array(
                                'co_title'                      =>
$form->getValue('title'),
                                'co_firstname'          =>
$form->getValue('firstname'),
                                'co_lastname'           =>
$form->getValue('lastname'),
                                'co_companyname'        =>
$form->getValue('companyname'),
                                'co_email'                      =>
$form->getValue('email'),
                                'co_querytext'          =>
$form->getValue('querytext')
                        );
                        $contactid = $contact->insert($data);
                        
                        // Insert the query area into contact_area
                        if ($form->getValue('queryarea'))
                        {
                                // Match the query area to contct_categories
and insert.
                                // loop through the query area array and
find update
                                foreach ($form->getValue('queryarea') as
$key)
                                {
                                        // Create a zend_db_table instance
of contact category
                                        $contactCategory = new
ContactCategory();
                                        // find the id of the key passed
from the form
                                        $catid =
$contactCategory->fetchRow($contactCategory->select()->from($contactCategory
,'ct_id')
                                                        ->where('ct_name =
?',$key));
                                        // create an instance of our contact
area db
                                        $contactArea = new ContactArea();
                                        // fill out the data
                                        $contactAreaData = array(
 
'ca_co_id' => $contactid,
 
'ca_ct_id' => $catid->ct_id
                                                                        );
                                        // commit the data to the db
 
$contactArea->insert($contactAreaData);
                                }
                        }

Reply via email to