Page 1 of 1

How to get the 1st element from an array (in XML format)?

PostPosted: Fri Mar 13, 2009 10:07 am
by angie
Hi Steve,

I have a phone_numbers array (in XML format), I tried to get the 1st element from this array, but I failed.

I also tried to loop through the phone_numbers array:
{foreach from=$person.phone_numbers item=number key=type}
{$number.name}: {$number.number}
{/foreach}

I did not get any data.

Could you please advise me on both issues?

Thank you very much.

Angie

Clarify this question

PostPosted: Fri Mar 13, 2009 2:27 pm
by angie
In my phone_numbers field, I have the following information:

<array>
<XML_Serializer_Tag>
<name>Phone</name>
<number>778-782-9999</number>
</XML_Serializer_Tag>
<XML_Serializer_Tag>
<name>Fax</name>
<number>778-782-1111</number>
</XML_Serializer_Tag>
</array>

I want to get: Phone 778-782-9999 only.

I would appreciate if anyone could give me a hint on this.

Thanks.

Angie

PostPosted: Fri Mar 13, 2009 2:59 pm
by shannah
The best way to retrieve this information is via the Dataface_Record object. But in your example, you're just working with an array that you loaded from the database.

In the Physics_Site class where you load the rows, you need to wrap the row in a Dataface_Record object to retrieve the values as an array.

e.g.

$rec = new Dataface_Record('people', $row);
$phoneNumbers = $rec->val('phone_numbers');

PostPosted: Fri Mar 13, 2009 3:49 pm
by angie
Hi Steve,

Thank you for your quick reply. I have fixed it.

Angie