News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

get value from product_attribute field [SOLVED]

Started by guardiano78, June 28, 2017, 09:41:49 AM

Previous topic - Next topic

guardiano78

Hello,
i need to make a external script that read only the value of product attribute from #__virtuemart_order_items table.

this is my product_attribute string value:

{
    "1": {
        "2": {
            "comment": "AJ4F9F"
        }
    }
}


Well, i need to extract from this string only AJ4F9F.

How can i do this?
thanks!

guardiano78

I tried with this code:

$stringa = '{
    "1": {
        "2": {
            "comment": "AJ4F9F"
        }
    }
}';

preg_match_all('/".*"/', $stringa, $ris);
$a= $ris[0][2];
$data = explode(':', $a);
echo str_replace('"','',$data[1]);

But i don't know if this is the right solution.
Can anyone help me?

Thank you!

Ghost

#2
That's probably JSON data. Use json_decode to turn it into object or array.

This works if you just need to echo the comment once:

echo json_decode($stringa,true)[1][2]['comment'];

guardiano78

Thank you for suggestion.
Now i used this code:

$data_attribute = json_decode($product_attribute, true);
$code = $data_attribute ['1']['2']['comment'];

and seem it works.

Thank you so much!