Read:

http://api.cakephp.org/1.2/class_model.html#029fcc94396edba60df5648e7086e01d

Or:

http://api.cakephp.org/class_model.html#029fcc94396edba60df5648e7086e01d

(Don't know which version are you using)

Regards,

Pablo

On 8/9/07, kionae <[EMAIL PROTECTED]> wrote:
>
> Have you tried $household_id = $this->Household->field("id",
> array('id' => $match_userid)); instead?  That seems to work for me...
>
>
>
> On Aug 9, 1:34 pm, phalvrson <[EMAIL PROTECTED]> wrote:
> > True - I changed to use the buit-in functions - ie save()  but I still
> > have the same problem.  The problem is that the line "$household_id =
> > $this->Household->field("id", $match_userid);" doesn't always issue
> > it's underlying SQL SELECT `Household`.`id` FROM `households` AS
> > `Household` WHERE `Household`.`userid` = '115603'  statement - it
> > seems to assume that id is already set correctly or something....  Can
> > you please explain this behavior?  I've tried inserting a 
> > "$this->Household->create()"  prior to that statement to re-initialize
> >
> > things, but that seems to have no effect on this behavior....
> >
> > Latest controller code:
> >
> >         function process_csv_file()
> >         {
> >                 $this->pageTitle = 'Process CSV File';
> >                 $checkFileFields = Array ( "id", "Item", "Qty", 
> > "Household", "HHID",
> > "FirstName", "LastName", "UserID", "Processed", "SchoolLocation",
> > "HouseholdEmail", "Address1", "Address2", "City", "State", "Zip",
> > "REFERENCE#2" );
> >                 if (!empty($this->params['form'])) {
> >                 $file_handle = fopen($this->params['form']['File']
> > ['tmp_name'],"r");
> >                         $label_fields = fgetcsv ($file_handle);
> >                         $last_household_id = null;
> >                         if ($checkFileFields == $label_fields) {
> >                                 $last_processed_student = null;
> >                                 $current_order_id = null;
> >                                 while (!feof($file_handle)) {
> >                                         $csv_fields = fgetcsv 
> > ($file_handle);
> >                                         /* Remember who we are processing - 
> > one order per student */
> >                                         $first_name = $csv_fields[5];
> >                                         $last_name = $csv_fields[6];
> >                                         $check_name = $first_name . ' ' . 
> > $last_name;
> >                                         /* Process the households db part. 
> > */
> >                                         $this_userid = $csv_fields[7];
> >                                         $match_userid = "Household.userid = 
> > '" . $this_userid . "'";
> >                                         $household_id = 
> > $this->Household->field("id", $match_userid);
> >                                         if (($household_id) || 
> > ($this->Household->exists())) {
> >                                                 /* Nothing to do - already 
> > have household id */
> >                                         } else {
> >                                                 
> > $this->data['Household']['last_name'] = $last_name;
> >                                                 
> > $this->data['Household']['HHID'] = $csv_fields[4];
> >                                                 
> > $this->data['Household']['userid'] = $this_userid;
> >                                                 
> > $this->data['Household']['email'] = $csv_fields[10];
> >                                                 
> > $this->data['Household']['address_1'] = $csv_fields[11];
> >                                                 
> > $this->data['Household']['address_2'] = $csv_fields[12];
> >                                                 
> > $this->data['Household']['city'] = $csv_fields[13];
> >                                                 
> > $this->data['Household']['state'] = $csv_fields[14];
> >                                                 
> > $this->data['Household']['zipcode'] = $csv_fields[15];
> >                                                 $this->Household->save( 
> > $this->data);
> >                                                 $household_id = 
> > $this->Household->getLastInsertID();
> >                                         }
> >                                         print_r($household_id);
> >                                         print_r($this->Household->id);
> >                                         /* Process the students db part. */
> >                                         $match_student_name = 
> > "Student.first_name = '$first_name' AND
> > Student.last_name = '$last_name' ";
> >                                         $student_id = 
> > $this->Student->field("id", $match_student_name);
> >                                         if (($student_id) || 
> > ($this->Student->exists())) {
> >                                                 /* Nothing to do - already 
> > have student id */
> >                                         } else {
> >                                                 
> > $this->data['Student']['first_name'] = $first_name;
> >                                                 
> > $this->data['Student']['last_name'] = $last_name;
> >                                                 
> > $this->data['Student']['household_id'] = $household_id;
> >                                                 
> > $this->data['Student']['school_location'] = $csv_fields[9];
> >                                                 $this->Student->save( 
> > $this->data);
> >                                                 $student_id = 
> > $this->Student->getLastInsertID();
> >                                         }
> >                                         print_r($student_id);
> >
> >                                         $csv_records[] = $csv_fields;
> >                                 }
> >                                 fclose($file_handle);
> >                         } else {
> >                                 echo "Mismatched File";
> >                         }
> >                 }
> >                 $this->set('csv_records', $csv_records);
> >         }
> >
> > Latest Model:
> >
> > class Household extends AppModel
> > {
> >         var $name = 'Household';
> >
> > }
> >
> > SQL output:
> > 2       DESCRIBE `orders`
> > 3       DESCRIBE `order_items`
> > 4       DESCRIBE `households`
> > 5       DESCRIBE `students`
> > 6       DESCRIBE `products`
> > 7       SELECT `Household`.`id` FROM `households` AS `Household` WHERE
> > `Household`.`userid` = '115603' LIMIT 1
> > 8       INSERT INTO `households`
> > (`last_name`,`HHID`,`userid`,`email`,`address_1`,`city`,`state`,`zipcode`)
> > VALUES ('Miller',14821,'115603','[EMAIL PROTECTED]','123 Main
> > St','Laveen','AZ','85339')
> > 9       SELECT LAST_INSERT_ID() AS insertID
> > 10      SELECT `Student`.`id` FROM `students` AS `Student` WHERE
> > `Student`.`first_name` = 'Bill' AND `Student`.`last_name` = 'Miller'
> > LIMIT 1
> > 11      INSERT INTO `students`
> > (`first_name`,`last_name`,`household_id`,`school_location`) VALUES
> > ('Bill','Miller',1,'ACA')
> > 12      SELECT LAST_INSERT_ID() AS insertID
> > 13      SELECT `Household`.`id` FROM `households` AS `Household` WHERE
> > `Household`.`userid` = '126448' LIMIT 1
> > 14      SELECT COUNT(id) AS count FROM `households` WHERE `id` = 1
> > 15      SELECT `Student`.`id` FROM `students` AS `Student` WHERE
> > `Student`.`first_name` = 'John' AND `Student`.`last_name` = 'Wilson'
> > LIMIT 1
> > 16      SELECT COUNT(id) AS count FROM `students` WHERE `id` = 1
> > 17      SELECT `Household`.`id` FROM `households` AS `Household` WHERE
> > `Household`.`userid` = '136285' LIMIT 1
> > 18      SELECT COUNT(id) AS count FROM `households` WHERE `id` = 1
> > 19      SELECT `Student`.`id` FROM `students` AS `Student` WHERE
> > `Student`.`first_name` = 'Jonathan' AND `Student`.`last_name` =
> > 'Bradford' LIMIT 1
> > 20      SELECT COUNT(id) AS count FROM `students` WHERE `id` = 1
> > 21      SELECT COUNT(id) AS count FROM `households` WHERE `id` = 1
> > 22      SELECT COUNT(id) AS count FROM `students` WHERE `id` = 1
> > 23      SELECT COUNT(id) AS count FROM `households` WHERE `id` = 1
> > 24      SELECT COUNT(id) AS count FROM `students` WHERE `id` = 1
> > 25      SELECT COUNT(id) AS count FROM `households` WHERE `id` = 1
> > 26      SELECT COUNT(id) AS count FROM `students` WHERE `id` = 1
> > 27      SELECT COUNT(id) AS count FROM `households` WHERE `id` = 1
> > 28      SELECT COUNT(id) AS count FROM `students` WHERE `id` = 1
> > 29      SELECT COUNT(id) AS count FROM `households` WHERE `id` = 1
> > 30      SELECT COUNT(id) AS count FROM `students` WHERE `id` = 1
> > 31      SELECT `Household`.`id` FROM `households` AS `Household` WHERE
> > `Household`.`userid` = '144970' LIMIT 1
> > 32      SELECT COUNT(id) AS count FROM `households` WHERE `id` = 1
> > 33      SELECT `Student`.`id` FROM `students` AS `Student` WHERE
> > `Student`.`first_name` = 'Paula' AND `Student`.`last_name` = 'Rondo'
> > LIMIT 1
> > 34      SELECT COUNT(id) AS count FROM `students` WHERE `id` = 1
> > 35      SELECT COUNT(id) AS count FROM `households` WHERE `id` = 1
> > 36      SELECT COUNT(id) AS count FROM `students` WHERE `id` = 1
> >
> > On Aug 9, 7:03 am, "Chris Hartjes" <[EMAIL PROTECTED]> wrote:
> >
> > > On 8/8/07, phalvrson <[EMAIL PROTECTED]> wrote:
> >
> > > > The Household Model:
> >
> > > > class Household extends AppModel
> > > > {
> > > >         var $name = 'Household';
> > > >         /* Creates new record in households and returns it's ID */
> > > >         function createRecord ($last_name, $HHID, $userid, $email,
> > > > $address_1, $address_2, $city, $state, $zipcode)
> > > >         {
> > > >                 $execString = "INSERT households SET ";
> > > >                 $execString .= " last_name = '" . $last_name . "',";
> > > >                 $execString .= " HHID = '" . $HHID . "',";
> > > >                 $execString .= " userid = '" . $userid . "',";
> > > >                 $execString .= " email = '" . $email . "',";
> > > >                 $execString .= " address_1 = '" . $address_1 . "',";
> > > >                 $execString .= " address_2 = '" . $address_2 . "',";
> > > >                 $execString .= " city = '" . $city . "',";
> > > >                 $execString .= " state = '" . $state . "',";
> > > >                 $execString .= " zipcode = '" . $zipcode . "'";
> > > >                 $this->execute($execString);
> > > >                 return;
> > > >         }
> > > > }
> >
> > > Why aren't you using the built-in Model functions?  For what you are
> > > doing there is no need for custom SQL queries.
> >
> > > --
> > > Chris Hartjes
> > > Senior Developer
> > > Cake Development Corporation
> >
> > > My motto for 2007:  "Just build it, damnit!"
> >
> > > @TheBallpark -http://www.littlehart.net/attheballpark
> > > @TheKeyboard -http://www.littlehart.net/atthekeyboard
>
>
> >
>


-- 
Pablo Viojo
[EMAIL PROTECTED]
http://pviojo.net

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to