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

A place for users and developers of the Xataface to discuss and receive support.

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

Postby angie » Fri Mar 13, 2009 10:07 am

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
angie
 
Posts: 12
Joined: Fri Mar 13, 2009 9:45 am

Clarify this question

Postby angie » Fri Mar 13, 2009 2:27 pm

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
angie
 
Posts: 12
Joined: Fri Mar 13, 2009 9:45 am

Postby shannah » Fri Mar 13, 2009 2:59 pm

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');
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby angie » Fri Mar 13, 2009 3:49 pm

Hi Steve,

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

Angie
angie
 
Posts: 12
Joined: Fri Mar 13, 2009 9:45 am


Return to Xataface Users

Who is online

Users browsing this forum: Google [Bot] and 15 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved