Solved

How to reference PHP sub-arrays to add to MySQL table

Posted on 2014-04-22
2
404 Views
Last Modified: 2014-04-22
I'm working with a NuSOAP client to bring back data from a web service.  The array I get back looks like this (shortened for readability):

Array
(
    [count] => 1
    [data] => Array
        (
            [0] => Array
                (
                    [accountCreatedDate] => 2014-03-04T23:49:39.459Z
                    [accountDefinedValues] => Array
                        (
                            [0] => Array
                                (
                                    [dataType] => 0
                                    [displayType] => 2
                                    [fieldName] => Attributes
                                    [fieldRef] => 24281.0.2664
                                    [value] => Sample Attribute
                                    [valueRef] => 24281.0.5668899
                                )

                        )
                )
        )
) 

Open in new window


I currently have the following set up to look for values in the Attributes array so I can add them all to one field in MySQL as a comma-separated list:

                foreach ($data['accountDefinedValues'] as $arr)
                {
                    if ($arr['fieldName'] != 'Attributes') continue;
                    $qry->attributes = $qry->attributes.$arr['value'].", ";
                    break;
                }

Open in new window



The problem I'm having is that the $qry->attributes variable is only capturing one of the values.  There could be 20 different Attributes that are brought back under the accountDefinedValues array.  

How do I loop through or concat all of them into the $qry->attribues field as a comma-separated list?

Help is much appreciated.
0
Comment
Question by:Carlos Elgueta
  • 2
2 Comments
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 40016050
Remove "break;" from the code!  All of the PHP instructions are documented online in the man pages.  If you're not 100% sure what an instruction is doing, you can look it up.  Example here:
http://php.net/manual/en/control-structures.break.php
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40016304
I love questions that have a quick solution.  Thanks for the points and thanks for using EE, ~Ray
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now