For loops json data to html for repeated output

        var data = {
            "message":"",
            "error":"false",
            "human":[
                {
                    "title":"",
                    "title_r":"8/23",
                    "msg":[
                        {
                            "name":"",
                            "name_r":"",
                            "content":"5/",
                            "content_r":"3-5",
                            "contents":"2018-02-07 19:23:37",
                            "contents_r":"20",
                            "address":"183",
                            "address_r":"25.36KM"
                        }
                    ]
                },
                {
                    "title":"",
                    "title_r":"25/108",
                    "msg":[
                        {
                            "name":"",
                            "name_r":"10/",
                            "content":"",
                            "content_r":"1",
                            "contents":"",
                            "contents_r":"256",
                            "address":"",
                            "address_r":""
                        }
                    ]
                },
                {
                    "title":"",
                    "title_r":"1/12",
                    "msg":[
                        {
                            "name":"",
                            "name_r":"10,568",
                            "content":"1.1 5% 10%",
                            "content_r":"100",
                            "contents":"50,000 95/",
                            "contents_r":"16,000",
                            "address":"",
                            "address_r":""
                        }
                    ]
                }
            ]
            };
            var country;
            var amount;
            var people;
            var html_box = "";
            var html_top = "";
            var html_bot = "";
            var object;
            var count = 0;
            var imgHTM="<img src="../web/img/list-img.jpg">";
            for(x in data["human"]){
                countPP;
                object = data["human"][x];
                console.log(object);
                country = object["title"];
                amount = object["title_r"];
                people = object["msg"];

                div_box = "<div class="m-content">";
                div_country = "<div class="m-c_title">";
                html_top += div_country+"<h1 id="attitle" class="fl">"+country+"</h1>"+"<p id="attitle_r" class="fr">"+amount+"

"; html_top+="</div>"; html_bot += "<div class="m-c_content">"; for(m in people){ person = people[m]; html_bot += imgHTM; html_bot += "<p class="m-c_top"><span class="m-c_t">"+person["name"]+"<span><span class="fr">"+person["name_r"]+"</span>

"; html_bot += "

"+person["content"]+"<span><span class="fr">"+person["content_r"]+"</span>

"; html_bot += "

"+person["contents"]+"<span><span class="fr">"+person["contents_r"]+"</span>

"; html_bot += "<p class="address">"+person["address"]+"<span><span class="fr">"+person["address_r"]+"</span>

"; html_bot += "</div>"; } html_box += div_box+html_top+html_bot+"</div>"; } $("-sharpcontainer").html(html_box);

I want to loop out these three sets of data to html, but for loops out repeated output like 1Magne12123.

Mar.06,2021

the following is your answer after revising the question:
in the case of your layout, in fact, the first, second and third groups should have the same layout. There is no need to make that complicated two-layer loop. One cycle is fine.

        var tpl = '';
        var count = 0;
        var imgHTM = "<img src='../web/img/list-img.jpg'>";
        $.each(data.human, function (i, item) {
            var human = item;
            var people = item.msg[0];
            tpl += '<div class="m-content">'+
            '<div class="m-c_title">'+
                '<h1 id="attitle" class="fl">'+ human.title +'</h1>'+
                '<p id="attitle_r" class="fr">'+ human.title_r +'

'+ '</div>'+ '<div class="m-c_content">'+ '<img src="../web/img/list-img.jpg">'+ '<p class="m-c_top">'+ '<span class="m-c_t">'+ people.name + '<span>'+ '<span class="fr">'+ people.name_r +'</span>'+ '</span>'+ '</span>'+ '

'+ '

'+ people.content + '<span>'+ '<span class="fr">'+ people.content_r +'</span>'+ '</span>'+ '

'+ '

'+ people.contents +''+ '<span>'+ '<span class="fr">'+ people.contents_r +'</span>'+ '</span>'+ '

'+ '<p class="address">'+ people.address + '<span>'+ '<span class="fr">'+ people.address_r +'</span>'+ '</span>'+ '

'+ '</div>'+ '</div>'; }); $("-sharpcontainer").html(tpl);

in the case of spelling html like this, it's best to find a template language to replace it


JSON is in the wrong format. The first object in the human array has an array of msg attributes, but the last two objects are called people.


there are deletions on your code.
`
var object;
var count = 0;
var html_box = "";
for (x in data ['human']) {
var html_top = ";
var html_bot =";
countPP;
object = data'human';
console.log (object);
var title = object [' title'];
var title_r = object ['title_r'];
var msg = object [' msg'];
countPP;
object = data'human';
console.log (object);
var title = object ['title'];
var title_r = object [' title_r'];
var msg = object [msg'])
div_box = "< div class='content' >";
html_top = "< div class='title' >";
html_top + = "< H1 >" + title + "< / H1 >" + "

" + title_r + "

";
html_top + = "< / div >";
for (m in msg) {

var childContent = "<div class='m-c_content'>";
person = msg[m];
childContent += "

<span>" + person['name'] + "<span><span>" + person['name_r'] + "</span>

"; childContent += "

" + person['content'] + "<span><span>" + person['content_r'] + "</span>

"; childContent += "

" + person['contents'] + "<span><span>" + person['contents_r'] + "</span>

"; childContent += "

" + person['address'] + "<span><span>" + person['address_r'] + "</span>

"; childContent += "</div>"; html_bot += childContent;

}

html_box + = div_box + html_top + html_bot + "< / div >";
}
$("- sharpcontainer") .html (html_box); `

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b31a9b-2bda3.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b31a9b-2bda3.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?