Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8002095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:15:53+00:00 2026-06-04T16:15:53+00:00

This code takes data from a php file which is doing a json_encode, which

  • 0

This code takes data from a php file which is doing a json_encode, which is pulling info from a csv file. I would like a parent div around each group of values within the second loop. I tried this with the newDiv2, but it wrapped each .field with .sub_row.

Instead of this:

 <div class="row"> // This one happens to only have one payment
     <div class="sum_field">Total: 79.99</div>
          <div class="field">BENV5239</div> // Details of payment
          <div class="field">11111</div>
</div>
 <div class="row"> // Based on Vendor ID
     <div class="sum_field">Total: 2487.01</div> // Sums up all payments for that Vendor
     <div class="field">BENV2137</div>
     <div class="field">11111</div>
     <div class="field">BENV2137</div>
     <div class="field">111111</div>
</div>
<div class="row"></div> // Another Vendor ID

It should be this:

 <div class="row">
     <div class="sum_field">Total: 200.00</div>
     <div class="sub_row">  // one payment
          <div class="field">BENV5239</div> // Details of payment
          <div class="field">11111</div>
     </div>
</div>
 <div class="row">
     <div class="sum_field">Total: 2487.01</div>
  <div class="sub_row"> // each payment that has the same vendor id is in it's own div
     <div class="field">BENV2137</div> 
     <div class="field">11111</div>
 </div>
 <div class="sub_row">
     <div class="field">BENV2137</div>
     <div class="field">111111</div>
 </div>
</div>

PHP Code

 $(document).ready(function() {
 $.getJSON('WF-XML.php', function(data) {

    //JSON.stringify(data); 
    var prevCardCode = '';
    var newDiv;

    $.each(data, function(index, element) {
        if (element['CardCode'] != prevCardCode) {
            newDiv = $('<div/>').addClass('row').appendTo('#showdata');
            $('<div class="sum_field">' + 'Total: ' + element['payment_sum'] + '</div>').appendTo(newDiv);      
            }
        prevCardCode = element['CardCode'];

        $.each(element, function(key, value) {

            switch (key) {
                case 'InvKey':
                case 'PostDate':
                case 'City':
                break;

                default:
                //newDiv2 = $('<div/>').addClass('sub_row').appendTo('.row');
                $('<div class="field">' + value + '</div>').appendTo(newDiv);
                break;
                 }
             });
         });
     });
  });

JSON – I’m looping through this twice, the first time I’m only printing the sum (which is being calculated within the SQL and the second time to print out the rest of the info. You can see the the last 2 objects are for the same Vendor Id – therefore I would like this to put a parent div around each new Vendor and then each individual payment. My code is already wrapping each group of payment going out to one vendor with a parent div, but I can’t figure out how to wrap each individual payment with a parent div.

 {"VendorID":"BENV5239","payment_sum":"79.99","Address":"525 Sapper St.","ZipCode":"19116"},
 {"VendorID":"BENV2137","payment_sum":"2487.01","InvPayAmnt":"108.92","Address":"340 Middle Road","ZipCode":"19037"},
 {"VendorID":"BENV2137","payment_sum":"2487.01","InvPayAmnt":"57.60","Address":"340 North Middle Road","ZipCode":"19037"}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:15:55+00:00Added an answer on June 4, 2026 at 4:15 pm
     $(document).ready(function() {
     $.getJSON('WF-XML.php', function(data) {
    
    //JSON.stringify(data); 
    var prevCardCode = '';
    var newDiv;
    
    $.each(data, function(index, element) {
        if (element['CardCode'] != prevCardCode) {
            newDiv = $('<div/>').addClass('row').appendTo('#showdata');
            $('<div class="sum_field">' + 'Total: ' + element['payment_sum'] + '</div>').appendTo(newDiv);      
            }
        newDiv2 = $('<div/>').addClass('sub_row').appendTo(newDiv);
        prevCardCode = element['CardCode'];
    
        $.each(element, function(key, value) {
    
            switch (key) {
                case 'InvKey':
                case 'PostDate':
                case 'City':
                break;
    
                default:
                //newDiv2 = $('<div/>').addClass('sub_row').appendTo('.row');
                $('<div class="field">' + value + '</div>').appendTo(newDiv2);
                break;
                 }
             });
         });
     });
    

    });

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my index file I get data from the database using this function (which
Problem Hello all! I have this code which takes my jpg image loops through
I use this code which is taken from MVC futures and attach the Attribute
I have a html file which select images from user's computer.code is given bellow
i found this code at activestate, it takes a string and prints permutations of
I have this small piece of code that basically takes a list and runs
I am using this code taken from here : import smtplib def prompt(prompt): return
This is a code sample taken from the Google Maps API developer's guide. I'm
I have a PayPal IPN PHP file set up which assigns all of the
I have Ajax file in which code has written to accept values form user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.