[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2014-04-22
2
Medium Priority
?
428 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 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 111

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
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 …
Suggested Courses

650 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