<?php
$tablesQuery = "SHOW TABLES";
$tablesResult = mysqli_query($conn, $tablesQuery);
$tables_count=mysqli_num_rows($tablesResult);
?>

<div class="content-header">
    <div class="container-fluid">
        <div class="row mb-2">
            <div class="col-sm-12">
                <h1 class="m-0" style="display: inline-block;">Database</h1>
                <div style="float: right; margin: -5px 4px 1px 18px; font-size: 17px;">
                    <a href="index?page=alter">
                        <i class="fa fa-edit"></i> <span>Alter</span>
                    </a>
                </div>
            </div>
        </div>
        <!-- /.row -->
    </div>
    <!-- /.container-fluid -->
</div>


<section class="content">
  <div class="container-fluid">
    <div class="row">
      <div class="col-lg-12">
	  <span id="rec_info_msg" style="font-weight: bold;"></span>
        <div class="card">
          <div class="card-body">
              <div class="table-responsive">
                <table id="example1" class="table table-bordered table-striped">
                  <thead>
                    <tr>
                      <th>Tables</th>
                      <th>No of Column</th>
                      <th>View</th>
                    </tr>
                  </thead>
                  <tbody>
                    <?
						$sum_cot=0;	
						while ($table = mysqli_fetch_assoc($tablesResult)) {
							$tableName = $table["Tables_in_" . $Database_name];
							$cl_cot=mysqli_query($conn,"SELECT COUNT(*) AS record_count FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '$Database_name' AND table_name = '$tableName' ");
							$countResult = mysqli_fetch_assoc($cl_cot);
							$cot=$countResult['record_count'];
							$sum_cot+=$cot;
					?>
                    <tr>
                      <td nowrap>
                        <a href="index?page=tables&table_name=
						<?=$tableName;?>" target="_blank"> <?php echo $tableName;?> </a>
                      </td>
					  <td><?=$cot;?></td>
					  <td nowrap>
                        <a href="index?page=tables_result&table_name=
						<?=$tableName;?>" target="_blank"> View </a>
                      </td>
                    </tr> 
					<? } ?>
                  </tbody>
				  <tfoot>
					  <td><span style="float:right;font-weight: bold;">Total Columns</span></td>
					  <td><?=$sum_cot;?></td>
					  <td></td>
				  </tfoot>
                </table>
              </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>

<script type="text/javascript">
$(function () {
  $(document).ready(function() {
   var dataTable = $('#example1').DataTable({
      paging: true,      
      lengthChange: true, 
      info: true,        
      ordering: false,
	  pageLength: 100	
    });
	
	var a=$("#example1_info").text();
	$('#rec_info_msg').text(a);
	
	dataTable.on('draw', function() {
        var b=$("#example1_info").text();
		$('#rec_info_msg').text(b);
    });
  });
});
</script>