PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 19, 2022

[FIXED] get data from field database

 January 19, 2022     database, php, phpmyadmin     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing