Issue
i want to ask
i have field example name of field is "orders" and in field orders have data like this (this field on phpmyadmin)
========
orders
========
{email":"tst@gmail.com","name":"myname","phone":"+123123123"}
how to get the data email, name, and phone?
in normal script to get data from field, example email like this :
<td>'.$row['email'].'</td>
but how to get the data if the contents of the field like that?
please help me,
thank you
Solution
As you want to access the values like array like this:
<td>'.$row['email'].'</td>
You should convert your data into array first, and then you can use it as array:
$json = json_decode($row['orders'], true); // 2nd argument `true` converts json object into array.
$email = $json['email'];
Or you can directly print inside HTML tags:
<td>'.$json["email"].'</td>
So, If you have more fields:
=========
country
=========
{"id":"001","country:"english","code:"123123"}
$order_json = json_decode($row['orders'], true);
$email = $order_json['email'];
$country_json = json_decode($row['country'], true);
$country = $country_json['country'];
Answered By - Himanshu Upadhyay
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.