Forums

Syntax for reading from database

cre8tivemedia 22 Dec, 2018
I'm displaying data onscreen from the database with the following code
 {var:read_data17.load_fields.title}
This is working correctly and displaying from the proper field.

I would like to pull data from the images field, specifically the subfield "image_fulltext_caption" as shown here in the database -



I just cannot figure out the proper syntax for it to work, I was thinking something like the following -
 {var:read_data26.load_fields2.images."image_fulltext_caption"}
I've tried a couple different things but can't get anything to work
healyhatman 22 Dec, 2018
It's JSON encoded so you have to json decode it first.
cre8tivemedia 24 Dec, 2018
I am able to display the entire field on screen, just trying to dig a little deeper.

This is what I have in the custom code
ID: {var:read_data17.load_fields.id}<br>
Introtext: {var:read_data17.load_fields.introtext}<br>
Created By Alias: {var:read_data17.load_fields.created_by_alias}<br>
Title: {var:read_data17.load_fields.title}<br>
Alias: {var:read_data17.load_fields.alias}<br>
CatID: {var:read_data17.load_fields.catid}<br>
Images: {var.jasonde:read_data17.load_fields.images}


This is is what it looks like on the front end, I would like to just display the "image_fulltext_caption" field



Frontend Link
healyhatman 25 Dec, 2018
Have you tried adding .image_fulltext_caption to that var call?
cre8tivemedia 25 Dec, 2018
Yes, I've tried
{var.jasonde:read_data17.load_fields.image_fulltext_caption}
and
{var.jasonde:read_data17.load_fields.images.image_fulltext_caption}
Just shows up blank
healyhatman 25 Dec, 2018
Do it in PHP then.
$images = json_decode($this-get("read_data17.load_fields.images"), true);
return $images["field_you_want"];

Then use {var:php_name}

Dont copy paste from forums though type manually
cre8tivemedia 25 Dec, 2018
Think I typed it in correctly but I'm just getting a spinning wheel when I execute...

This topic is locked and no more replies can be posted.