Home Extracting data correctly from an array for storage
Reply: 0

Extracting data correctly from an array for storage

user1322
1#
user1322 Published in May 25, 2018, 6:53 pm

In the following array I'm trying to extract each clothing type and the first "a" and "b" values from "results" array and then store the "a" and "b" values in to the clothing type column in my database.

The outputted array structure is as follows

Array ( [0] =>
{
    "error": [],
    "result": {
        "shirts": {
            "a": [
                "12",
                "6",
                "6.000"
            ],
            "b": [
                "91",
                "1",
                "1.000"
            ]
        },
        "pants": {
            "a": [
                "41",
                "3",
                "3.000"
            ],
            "b": [
                "55",
                "30",
                "30.000"
            ]
        }
    }
}
)

So the data should go something like: Insert 12 in to the shirts type column in column a and 91 in column b, and insert 41 in to the pants type column in column a and 55 in column b.

Where am I going wrong with this foreach loop?

foreach($result['result'] as $clothing) {
        $query = 'UPDATE `clothing` SET `a`='.$clothing["a"].' AND SET `B`='.$clothing["a"].' WHERE `type`="'.$clothing[0].'"';
        $result = db_query($query);
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.304859 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO