Thanks for all of the help. The tips I got pointed me in the right
direction. Once I changed my foreach loops to while (list($key,
$value) = each($patient['Visit'])) and while (list($key, $value) =
each($patient['M5Symptoms'])) respectively, my data appeared. I
figured this out once I realized the foreach() operates on a copy of
the array and list($key, $value) = each($array) doesn't.

http://us2.php.net/foreach
http://us2.php.net/manual/en/function.list.php

(Links for reference to those who might come upon this in the future.
Hello from the past.)

On May 15, 2:26 pm, Tony Thomas <[EMAIL PROTECTED]> wrote:
> OK, some additional information. (I apologize, because I think this is
> getting into PHP territory and may not be specifically related to
> CakePHP.)
>
> If I place debug($patient) before the first foreach loop (for
> 'Visit'), I get the arrays as below. If I place it after the foreach
> loop I get the same "Undefined index" message. How can I preserve that
> array to reuse it to make a second table?
>
> On May 15, 12:35 pm, Tony Thomas <[EMAIL PROTECTED]> wrote:
>
> > debug($patient) produces:
>
> > Array
> > (
> >     [Patient] => Array
> >         (
> >             [id] => 5007
> >             [med_hist_id] => 0
> >             [gender] => M
> >             [st_of_birth] => [redacted]
> >             [st_of_res] => [redacted]
> >             [res_length] => 11 yrs
> >             [cntry_of_origin] => U.S.
> >             [dob] => [redacted]
> >             [siblings] => 2
> >             [birth_order] => 1
> >             [mono_before] => N
> >             [ethnicity] => [redacted]
> >             [race] => [redacted]
> >             [contact_by] => email
> >             [withdrawn] => N
> >             [kdas] => NKDA
> >             [mono_dx] => N
> >         )
>
> >     [Visit] => Array
> >         (
> >             [0] => Array
> >                 (
> >                     [id] => 2060
> >                     [quest_id] =>
> >                     [patient_id] => 5007
> >                     [protocol] => Mono 5
> >                     [vdate] => 4/22/2008
> >                     [vtmstmp] => 1208840400
> >                     [week] =>
> >                     [yr] => 2
> >                     [number] => 8
> >                     [notes] => [redacted]
> >                     [kit] => 0
> >                     [sev_p] => 0
> >                     [sev_scr] => 0
> >                     [sev_pain] =>
> >                     [modified] => 4/22/2008 2:25:47 PM
> >                     [created] => 4/22/2008 2:11:39 PM
> >                 )
> > //truncated here, but shows the last ten visits as expected
>
> >         )
>
> >     [M5Symptom] => Array
> >         (
> >             [0] => Array
> >                 (
> >                     [id] => 19
> >                     [patient_id] => 5007
> >                     [symptom] => Stuffy Nose
> >                     [start_date] => 12/18/2006
> >                     [end_date] => 12/21/2006
> >                     [severity] =>
> >                     [exported] =>
> >                     [date_reported] =>
> >                     [created] =>
> >                     [modified] =>
> >                 )
> > // again truncated by me, but the list of 25 shows up in the array
>
> >         )
>
> > )
>
> > On May 15, 12:23 pm, "[EMAIL PROTECTED]"
>
> > <[EMAIL PROTECTED]> wrote:
> > > Hi Tony,
> > > What do you have in the $patient variable when you debug it?
> > > debug($patient)
>
> > > /Martin
>
> > > On May 15, 5:37 pm, Tony Thomas <[EMAIL PROTECTED]> wrote:
>
> > > > Hi All,
>
> > > > I'm building a CakePHP app for tracking clinic patients, their visits,
> > > > their symptoms and questionnaire answers. The barrier I've encountered
> > > > is that each patient has many visits AND many symptoms. I want to view
> > > > the patient record and their aggregate visits and symptoms.
>
> > > > I've defined a hasMany relationship in the patient model as such:
>
> > > > var $hasMany = array(
> > > >         'Visit' => array(
> > > >             'order'    => 'Visit.id DESC',
> > > >             'limit'        => '10'
> > > >         ),
> > > >         'M5Symptom' => array(
> > > >                 'className' => 'M5Symptom',
> > > >                 'order' => 'M5Symptom.modified DESC',
> > > >                 'limit' => '25'
> > > >         )
> > > >     );
>
> > > > In the patient view I get the relevant patient data, and the
> > > > corresponding list of visits, but I get the message, "Undefined
> > > > index:  M5Symptom" for listing the symptoms. As far as I can tell the
> > > > model is correct, because the query for the patient view finds and
> > > > retrieves a list of 25 symptom records exactly as specified in the
> > > > model. From that I take that the model and controller must be working
> > > > as expected. Otherwise the query wouldn't be right and/or it wouldn't
> > > > retrieve the pertinent records. The query that results is EXACTLY what
> > > > I want.
>
> > > > That leads me to believe the problem must be in the view.
>
> > > > Here's the view function in the patient controller:
>
> > > > function view($id = null) {
>
> > > >                 $this->Patient->id = $id;
> > > >                 $this->set('patient', $this->Patient->read());
>
> > > >         }
>
> > > > Everything works right up until I try to list the symptoms. Here's the
> > > > code for listing symptoms in the view:
>
> > > > echo $html->tableHeaders(array('Symptom','Start Date','End Date',
> > > > 'Severity'));
>
> > > > foreach ($patient['M5Symptom'] as $symptom) {
>
> > > >         echo $html->tableCells(
>
> > > >         array($symptom['symptom'],
> > > >               $symptom['start_date'],
> > > >               $symptom['end_date'],
> > > >               $symptom['severity'],
> > > >         )
> > > >         );
>
> > > > }
>
> > > > I've looked at all of this over and over and I just can't find out why
> > > > 'M5Symptom' is undefined. Just above this, 'Visit' lists recent visit
> > > > dates for me with the exact same logic in place.
>
> > > > Am I wrong in assuming I can define more than one hasMany? If so, why
> > > > is the correct query generated? I'm hoping another set of eyes will
> > > > find what I'm missing. Sleeping on it didn't help.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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