Solved

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

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

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 110

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
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…

724 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