Create Top Rental Tables
#\controllers\toprental.py
import config, re, json
from bottle import template, route, request, redirect
from models import registerdb

@route('/toprental')
def getTopRental():
  config.kargs['toprentals'] = json.dumps(registerdb.getTopRental())
  return template('toprental', data=config.kargs)
def getTopRental():
  conn = sqlite3.connect('sqlite.db')
  cursor = conn.cursor()

  sql = "SELECT CUSTOMER, COUNT(*) FROM REGISTER GROUP BY CUSTOMER ORDER BY COUNT(*) DESC LIMIT 10"

  cursor.execute(sql)
  customers = cursor.fetchall()

  sql = "SELECT BRAND, COUNT(*) FROM REGISTER GROUP BY BRAND ORDER BY COUNT(*) DESC LIMIT 10"

  cursor.execute(sql)
  brands = cursor.fetchall()
  
  conn.commit()
  conn.close()

  return (customers, brands)
<!--\views\toprental.tpl-->

%include("./partials/header.tpl")

<div class="main" id="main">
  <div class="content" id="content">
    <div class="top-widget">
    <span>TOP RENTAL</span>
    </div>
    
    <div id="table-customer"></div>
    <div id="table-bicycle"></div>
    <script src="/static/scripts/jQuery.js"></script>
    <script src="/static/scripts/main.js"></script>
    <script>
      $(document).ready(function() {
        bicycle.showTopRental({{!data['toprentals']}});
      });
    
    </script>
    
  </div><!--content-->

</div><!--main-->

%include("./partials/footer")
showTopRental(toptentals){
    var customers = toptentals[0];
    var brands = toptentals[1];
    var html = '';
    
    if(customers.length > 0){
      html += "<table>";
      html += "<tr>";
      for(var k in {rate:1, 'top customers':1}){
        html += "<th>" + k.toUpperCase() + "</th>";
      }
      html += "</tr>";

      for(var i=0; i<customers.length; i++){
        html += "<tr>";
        html +=  "<td style='width:80px;text-align:center;'>" + (i+1) + "</td>";
        html += "<td>" + customers[i][0] + "</td>";
        html += "</tr>";
      }
      html += "</table>";
    }
    document.getElementById("table-customer").innerHTML = html;

    if(brands.length > 0){
      html = '';
      html += "<table>";
      html += "<tr>";
      for(var k in {rate:1, 'popular bicycles':1}){
        html += "<th>" + k.toUpperCase() + "</th>";
      }
      html += "</tr>";

      for(var i=0; i<brands.length; i++){
        html += "<tr>";
        html +=  "<td style='width:80px;text-align:center;'>" + (i+1) + "</td>";
        html += "<td>" + brands[i][0] + "</td>";
        html += "</tr>";
      }
      html += "</table>";
    }
    document.getElementById("table-bicycle").innerHTML = html;
  }

GitHub: https://github.com/Sokhavuth/Rental-Bicycle-App
Heroku: https://khmerweb-rba.herokuapp.com/