Solved

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

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

829 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