Pulling json formatted data from table and accessing info within that data

How do i work with this data ?

above is the column

below is the data structure in this column

data structure
i am formatting it as json in the column but how do i access is on php from i pull it from the data and select the values of ids i want ?
Alex LordAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Do something like this...

$obj = json_decode($json);

Open in new window

Then access $obj data as a nested hash... maybe like...

$campaign = $obj->{"output"}->{"campaign"};

$obj->{"output"}->{"campaign"} = "new-campaign-name";

Open in new window

Chris StanyonWebDevCommented:
Assuming you already have a PDO connection to your DB, something like this maybe:

$data = $db->query("SELECT CHANNEL FROM yourTable WHERE id = 1");
$json = $data->fetchColumn();

$channel = json_decode($json);

Open in new window

That will pull the CHANNEL data from your table where the Record ID is 1 (filter the query anyway you like). It then json_decodes that data into an object called $channel. You can then access the data like any other object:

echo $channel->referrer;
echo $channel->output->campaign;
echo $channel->output->channel;
echo $channel->output->type;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.