Ty Alexandru for your help.I will use a little different block of code as i
tested it and it works fine.Beow is my code.where i take each geoname's
fields and save them in my db.

for ( $i = 1; $i <= 4; $i += 1) {
        /** total results**/
        $root=$xml->children[0]->children[0]->name;
        $total_results = $xml->children[0]->children[0]->children[0]->value;
        $this->data['Destination']['total_count'] = $total_results;
        $this->set('total_results',$total_results);

        /** Name of destination**/
        $nameof =
$xml->children[0]->children[$i]->children[0]->children[0]->value;
        $this->data['Destination']['name'] = $nameof;
        $this->set('name',$nameof);
        /** Latitude of destination**/
        $lat =
$xml->children[0]->children[$i]->children[1]->children[0]->value;
        $this->data['Destination']['lat'] = $lat;
        $this->set('lat',$lat);
        /** Longtitude of destination**/
        $lng =
$xml->children[0]->children[$i]->children[2]->children[0]->value;
        $this->data['Destination']['lng'] = $lng;
        $this->set('lng',$lng);
        /** Geoname-id of destination**/
        $geoid =
$xml->children[0]->children[$i]->children[3]->children[0]->value;
        $this->data['Destination']['geonameId'] = $geoid;
        $this->set('geoid',$geoid);
        /** Country code of destination**/
        $ctrcode =
$xml->children[0]->children[$i]->children[4]->children[0]->value;
        $this->data['Destination']['countryCode'] = $ctrcode;
        $this->set('code',$ctrcode);
        /** Country name of destination**/
        $ctrname =
$xml->children[0]->children[$i]->children[5]->children[0]->value;
        $this->data['Destination']['countryName'] = $ctrname;
        $this->set('ctrname',$ctrname);
        /** Fcl of destination**/
        $fcl =
$xml->children[0]->children[$i]->children[6]->children[0]->value;
        $this->data['Destination']['fcl'] = $fcl;
        $this->set('fcl',$fcl);
        /** Fcode of destination**/
        $fcode =
$xml->children[0]->children[$i]->children[7]->children[0]->value;
        $this->data['Destination']['fcode'] = $fcode;
        $this->set('fcode',$fcode);

        /*** saves the user_id **/
        $userId = $this->Session->read('Auth.User.id');
        $this->data['Destination']['user_id'] = $userId;

        /** saves the input data from user**/
        //$this->data['Destination']['place'] = $place;
        $this->Destination->saveAll($this->data);
        }

        $destinations = $this->Destination->find('all', array('conditions'
=> array('Destination.user_id =' => '142')));
        $this->set(compact('destinations'));

The only thing i want to fix in this code is the for where i want to loop
for the number of  children as well as in find to replace the "142" with
something like $this->Session->read('Auth.User.id') which it isn't work.


2009/7/15 Alexandru Ciobanu <[email protected]>

>
> On 07/14/2009 04:29 PM, Paulos23 wrote:
> >
> > How i can take these data from the array[] and print them like this
> > for example?
> > name:Barcelona
> > lat:...
> > lng...
> >
> Given $i is the name of your array.
>
> foreach($i['Geoname'] as $parent){
>             foreach($parent as $key => $child){
>                 echo $key, ': ', $child;
>             }
> }


>
> PS: Look into arrays; lots of resources available.
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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