1

I need to display the total number of rows(sum) in a DIV element. The number would express the sum of the data being toggled using the following function:

var LayerActions = {
  extortion: function(){

    sublayers[0].set({
        sql: "SELECT * FROM table1 where type <> 0",
    });
    return true;
  },
}
1
  • 1
    Welcome to gis.stackexchange! Please try to formulate a question. Also it helps if you can show the code you have tried so far to solve your problem.
    – ylka
    Commented Nov 24, 2016 at 12:47

2 Answers 2

1

You could use the CARTO SQL API to get and store in a variable all the rows of the result of a query like:

sql.execute("SELECT unnest(CDB_QuantileBins(array_agg(homes), 3)) FROM barris_barcelona_test") 
              .done(function(data){
                for(i = 0; i < data.total_rows; i++){ // loop that reads each column of the table
                  sum = sum + 1
}

Then you can use the .innerHTML method to display the result inside the DIV element. Here you can find an example that shows the number of rows of the dataset after selecting the option in the dropdown menu,

0
0

I just changed a little bit the expression to get the total number of rows every times the API is called. Then, as you said, the .innerHTML method would display the result inside the DIV element.

sql.execute("SELECT unnest(CDB_QuantileBins(array_agg(homes), 3)) FROM barris_barcelona_test") 

.done(function(data){ for(i = 0; i < data.total_rows; i++){//loop that reads each column of the table sum = data.total_rows }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.