The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

I wanna combine tables!

View previous topic View next topic Go down

I wanna combine tables!

Post by Voxie on 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>




Voxie
New Member

Male Posts : 9
Reputation : 2
Language : English

Back to top Go down

Re: I wanna combine tables!

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

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

Voxie
New Member

Male Posts : 9
Reputation : 2
Language : English

Back to top Go down

Re: I wanna combine tables!

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

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


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

avatar
SLGray
Administrator
Administrator

Male Posts : 37986
Reputation : 2561
Language : English
Location : United States

http://ztwds.forumotion.com/

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum