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 8982375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:33:48+00:00 2026-06-15T20:33:48+00:00

I am trying to show the record returned from my DB my returned data

  • 0

I am trying to show the record returned from my DB

my returned data is like the following:

UserID   Username    Fullname     ID
141        john       jerry1      170   
141        john       jerry1      18
141        john       jerry1      1169
110        ted       jerrytest    1701
110        ted       jerrytest    18

I want to show all the ID in the page but avoid the duplicated username

so it will be like

john    170
        18
        1169

ted     1701
        18
//I only want 2 divs (for john and ted) instead of 5. 

My codes currently show

john    170    //1 loop
john    18     //1 loop
john    1169   //1 loop

ted     1701   //1 loop
ted     18     //1 loop

My codes:

for(var i=0; i<results.length; i++){
  //create a div for each row...in my case, 5 divs/rows


//i tried to create a var a
   a=i-1;
   if(results[a]){
        if(results[i].Username==results[a].Username){
           continue;
        }
    }


//this will eliminate the duplicated john and ted but only show john 170 and ted 1701.

}

To recap, I want to show all the unique id in each row but not the duplcated username.
Are there better way to do this? Thanks a lot!

  • 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-15T20:33:50+00:00Added an answer on June 15, 2026 at 8:33 pm

    Why not combine both methods?

    var endResult = "",
        ids = [],
        userName;
    
    for (var i = 0, lt = results.length; i < lt; i++)
    {
        ids.push(results[i].ID);
        userName = (i === 0 || results[i].Username != results[i-1].Username) ? results[i].Username : false;
    
        if (userName)
        {
            endResult += "<div>" + userName + "</div>";
            endresult += "<div>" + ids.join("<br>") + "</div>"
    
            //Reset the list of ids
            ids = [];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to show a simple countdown from 2 hours like so: $(function ()
I'm trying to make my Listview show only one record just like how DetailsView
I'm trying to show a UIAlertView before actually deleting a cell from a UITableView
In MS Access I am trying to filter to show only records from previous
I'm trying to show the datagridview with only selected column from the xml The
I want to fill a DataGridView with data returned from a SQL. So here
I am trying to delete the all record from the table in database, but
I am trying to get hold of 1 record from a MySQL table using
I'm trying to create a form that will show the id that the record
I'm trying to show an image from a folder that the user selected.and if

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.