Solved

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

Posted on 2014-04-22
2
408 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 109

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 109

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

777 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