close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

JSON nested repeat region - how to do it?

Thread began 1/21/2017 7:01 pm by Janet | Last modified 1/23/2017 5:06 pm by Ray Borduin | 3088 views | 11 replies |

Janet

JSON nested repeat region - how to do it?

I have a database table with one field that contains JSON . Each row of the database contains simple text fields called fields called TITLE, SUBTITLE, and DESCRIPTION, and the JSON data field called IMAGE

When the IMAGE JSON contains one image the following code works, but I have no clue how to add the code that would nest repeat all the images included in the JSON field as images.

The code I am using for single images per row is:

<?php
while(!$DETAILS->atEnd()) {
?>

<div class="row">
<div class="col-md-8">
<h2><?php echo($DETAILS->getColumnVal("TITLE")); ?></h2>
<p><strong><?php echo($DETAILS->getColumnVal("SUBTITLE")); ?></strong></p>
<?php echo($DETAILS->getColumnVal("DESCRIPTION")); ?>

</div>
<div class="col-md-4">
<strong>

<?php

$json = $DETAILS->getColumnVal("IMAGE");
//

$myArray = json_decode($json, true);

?>
<?php if ($DETAILS->getColumnVal("IMAGE") != "") { ?>
<img src="input/<?php echo $myImage = $myArray[0]["name"]; ?>" class="img-responsive center-block" alt="<?php echo $DETAILS->getColumnVal("TITLE"); ?>">
<?php } ?>
</div>
</div>
<?php
$DETAILS->moveNext();
}
$DETAILS->moveFirst(); //return RS to first record
?>


An example of the 'multi-image' JSON is : [{"name":"images\/03_y8osnwim.jpg","usrName":"03.jpg","size":98665,"type":"image\/jpeg","thumbnail":"images\/th03_jdfcm55b.jpg","thumbnail_type":"image\/jpeg","thumbnail_size":11684,"searchStr":"03.jpg,!11.jpg,!01.jpg,!12.jpg,!02.jpg,!13.jpg,!05.jpg,!14.jpg,!06.jpg,!:sStrEnd"},{"name":"images\/11_ipi01ygc.jpg","usrName":"11.jpg","size":96945,"type":"image\/jpeg","thumbnail":"images\/th11_g5cqaao1.jpg","thumbnail_type":"image\/jpeg","thumbnail_size":12155},{"name":"images\/01_xv69cder.jpg","usrName":"01.jpg","size":98327,"type":"image\/jpeg","thumbnail":"images\/th01_bep2e90t.jpg","thumbnail_type":"image\/jpeg","thumbnail_size":11359},{"name":"images\/12_mhancpnr.jpg","usrName":"12.jpg","size":104597,"type":"image\/jpeg","thumbnail":"images\/th12_4et19bu1.jpg","thumbnail_type":"image\/jpeg","thumbnail_size":10972},{"name":"images\/02_j1bblk53.jpg","usrName":"02.jpg","size":123075,"type":"image\/jpeg","thumbnail":"images\/th02_midqduuw.jpg","thumbnail_type":"image\/jpeg","thumbnail_size":13143},{"name":"images\/13_8iawh5dk.jpg","usrName":"13.jpg","size":108840,"type":"image\/jpeg","thumbnail":"images\/th13_ghuqpvtj.jpg","thumbnail_type":"image\/jpeg","thumbnail_size":11991},{"name":"images\/05_ujgcogbd.jpg","usrName":"05.jpg","size":116858,"type":"image\/jpeg","thumbnail":"images\/th05_o319l82a.jpg","thumbnail_type":"image\/jpeg","thumbnail_size":12247},{"name":"images\/14_lftyibpj.jpg","usrName":"14.jpg","size":127039,"type":"image\/jpeg","thumbnail":"images\/th14_5bzrctsz.jpg","thumbnail_type":"image\/jpeg","thumbnail_size":11481},{"name":"images\/06_urku1k0z.jpg","usrName":"06.jpg","size":174727,"type":"image\/jpeg","thumbnail":"images\/th06_73yma7ny.jpg","thumbnail_type":"image\/jpeg","thumbnail_size":15751}]


Any advice you can give would be much appreciated. MySQLi and JSON newbie!

Sign in to reply to this post

Janet

Just to update with an answer and a follow up question...

I finally found out how to turn the JSON into a repeat region in the php... this is my code:

<?php
$someJSON = $DETAILS->getColumnVal("IMAGE");

$someArray = json_decode($someJSON, true);

foreach ($someArray as $key => $value) {
echo "<a href=\"input/\" " . $value["name"].
"<div class=\"col-md-4\" style=\"margin-bottom: 5px\"><img src=\"input/" . $value["name"]."\" class=\"img-responsive\"></a> </div>";
}

?>

and it works perfectly for the first row (web example sent privately)

But it won;t repeat the whole row - in fact, on every page I have added the json_decode the repeat region doesn't work.

Everything seems to be fine as far as I can see, I am not sure what I have done wrong. Can you advise? I have sent the pages as an attachment.

Thanks for a great product!

Sign in to reply to this post

Ray BorduinWebAssist

It looks like it should work to me. The only way I could debug any further would be to have a url and ftp access to a page where you have tried to do this and it isn't working. I could probably debug that and tell you why at that point.

Sign in to reply to this post
Did this help? Tips are appreciated...

Janet

With pleasure sir :) And with thanks too! Details attached privately.

Sign in to reply to this post

Ray BorduinWebAssist

What url should I be using to view the page with the problem?

Sign in to reply to this post
Did this help? Tips are appreciated...

Janet

www.sigwebdesign.com/boyce - it is a simple site and each page is very similar, each with its own database table

Sign in to reply to this post

Ray BorduinWebAssist

Just a little more background. So I'm assuming I should click on the gallery.php page and then on that page there are some missing images? Where is the problem that I'm supposed to be looking at? What is missing? What do you expect to see that you aren't seeing?

Sign in to reply to this post
Did this help? Tips are appreciated...

Janet

Hi Ray,

In the image gallery, and in the Christmas Trees page, there are two rows. The repeat region does not show the second rown. I started off this weekend asking about the json query, and finally found out my errors, but I can;t work out why the repeat region is not repeating.

Sign in to reply to this post

Ray BorduinWebAssist

Ok it is probably the same issue on both pages, so let's just work with one at a time anyway. I'm looking at the gallery page and I don't even see a repeat region applied.

Sign in to reply to this post
Did this help? Tips are appreciated...

Janet

on the trees.php page "Christmas Trees" it does have a repeart region, but doesn't show it.

I don't know why I did';t put the repeat region back on that gallery page. I removed it to solely work on the json section (so as not to confuse myself, as you can probably already imagine that is very easy to do)

I just know this is going to be something really stuupid I did wrong - been one of those weeks! LOL

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...