The forum of the forums

Would you like to react to this message? Create an account in a few clicks or log in to continue.
The forum of the forums
2 posters

    I wanna combine tables!

    avatar
    Voxie
    New Member


    Male Posts : 9
    Reputation : 2
    Language : English

    I wanna combine tables! Empty I wanna combine tables!

    Post by Voxie March 20th 2017, 6:03 pm

    hello guys i just basically saw some good website who alrdy combined 9 servers tables in 1 table including all votes from all server which is something perfect and i tried to do but i can't seem to work it out ! so

    the links of tables i have are


    https://ark-servers.net/api/?object=servers&element=voters&key=jwoy226r9qo29rxid0a9vg65pno4s9bsf29&month=current&format=json
    https://ark-servers.net/api/?object=servers&element=voters&key=4knryax7ibqp789k3tzjjjbmkxkl5ns9dh&month=current&format=json
    https://ark-servers.net/api/?object=servers&element=voters&key=7w41ryvms91repwbef222ccqsnoutiurray&month=current&format=json



    And i basically want these 3 tables there to be all in 1 table combined with all counts

    Lets say Target 1 Had on the first link 50 vote and on the second link 30 vote and the third 1 that makes it overall 81 Please someone help me solve that Smile i would be appreciated!

    this was the java code i used

    Code:
    <script>
       
       var votingURLs = [   
       'https://ark-servers.net/api/?object=servers&element=voters&key=jwoy226r9qo29rxid0a9vg65pno4s9bsf29&month=current&format=json',
       'https://ark-servers.net/api/?object=servers&element=voters&key=4knryax7ibqp789k3tzjjjbmkxkl5ns9dh&month=current&format=json',
       'https://ark-servers.net/api/?object=servers&element=voters&key=7w41ryvms91repwbef222ccqsnoutiurray&month=current&format=json',
       ];
       
       var votingLists = [];
       
       var counter = 0;
       
       var finalList = [];
       
       var voters = [];
       var votesOfVoters = [];
       
       
       $(document).ready(function () {
          

          $.each(votingURLs, function( index, value ) {
             
             
             var data;
             $.ajax({
                dataType: "json",
                url: value,
                data: data,
                success: function (data) {

                   console.log(data.voters);
                   votingLists[index] = data.voters;
                   

                   checkCompleteness();
                }
             });
                
          });
       });
       
       
       
       function checkCompleteness(){
          counter++;
             
          if(counter==(votingURLs.length)){
             evalData();
          }
       }
       
       
       function evalData(){
          console.log("Start Evaluating");
          finalList = votingLists[0];
          

          $.each(votingLists, function(index, list){
             if(index > 0){
                
          
                $.each(list, function(index, value){
                   

                   var name = value.nickname;
                   var found = false;         
                   
          
                   $.each(finalList, function(indexF, valueF){
                      


                      if(name == valueF.nickname){

                         valueF.votes = parseInt(valueF.votes) + parseInt(value.votes);
                         found = true;
                         return false;
                         
                      }
                   });
                   
                   //If not found, add it to the list
                   if(!found){
                      finalList.push(value);
                   }
                });
                
                
             }
          });
       
          displayingList(finalList);
       }
       
       
       
       function displayingList(list){
          console.log("Start Displaying");
          
          list.sort(function(a,b) {


               return parseInt(b.votes,10) - parseInt(a.votes,10);

          });
          
          $.each(list, function(index, value){
             

             var row = '<tr> <td>' + value.nickname + '</td> <td> ' + value.votes + '</td> </tr>';
             $('table[data="votingList"] tbody').append(row);
          });
       }
       </script>



    avatar
    Voxie
    New Member


    Male Posts : 9
    Reputation : 2
    Language : English

    I wanna combine tables! Empty Re: I wanna combine tables!

    Post by Voxie March 20th 2017, 6:26 pm

    I just made it i solved it thanks al ot Smile!
    SLGray
    SLGray
    Administrator
    Administrator


    Male Posts : 51498
    Reputation : 3523
    Language : English
    Location : United States

    I wanna combine tables! Empty Re: I wanna combine tables!

    Post by SLGray March 20th 2017, 6:38 pm

    Since the solution was not posted, this topic will be sent to the garbage.



    I wanna combine tables! Slgray10

    When your topic has been solved, ensure you mark the topic solved.
    Never post your email in public.

      Current date/time is September 23rd 2024, 4:21 am