Plugin Directory

Changeset 521388


Ignore:
Timestamp:
03/20/2012 05:04:35 PM (14 years ago)
Author:
Albert Bertilsson
Message:

Basic statistics added.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • database-peek/trunk/statistics.php

    r521032 r521388  
    1717            global $wpdb;
    1818           
     19            $tabletotal = $wpdb->get_var( "select count(*) from $table" );
    1920            $rows = $wpdb->get_results( "select * from $table where 1 = 0" );
    2021            $col_names = $wpdb->get_col_info('name');
     
    4546                    </tbody>
    4647                    </table>
     48                    <br>
    4749                    <?php
    4850                }
    4951
    5052
    51                 echo "<h4>Distinct values</h4>";
     53                echo "<strong>Distinct values:</strong> ";
     54                $res = $wpdb->get_var( "select count(distinct $n) from $table" );
     55                $percent = round(100 * $res / $tabletotal, 2);
     56                echo "$res ($percent%)<br>";
    5257
    5358
    54                 echo "<h4>Average length</h4>";
     59                echo "<strong>Average:</strong> ";
     60                $res = $wpdb->get_var( "select avg($n) from $table" );
     61                $res = round($res, 2);
     62                echo "$res<br>";
    5563
    5664
    57                 echo "<h4>Nulls</h4>";
     65                echo "<strong>Total:</strong> ";
     66                $res = $wpdb->get_var( "select sum($n) from $table" );
     67                $res = round($res, 2);
     68                echo "$res<br>";
     69
     70
     71                echo "<strong>Average length:</strong> ";
     72                $res = $wpdb->get_var( "select avg(length($n)) from $table" );
     73                $res = round($res, 2);
     74                echo "$res<br>";
     75
     76
     77                echo "<strong>Nulls:</strong> ";
     78                $res = $wpdb->get_var( "select count(*) from $table where $n is null" );
     79                $percent = round(100 * $res / $tabletotal, 2);
     80                echo "$res ($percent%)<br>";
     81
     82
     83                echo "<strong>Empty:</strong> ";
     84                $res = $wpdb->get_var( "select count(*) from $table where $n = ''" );
     85                $percent = round(100 * $res / $tabletotal, 2);
     86                echo "$res ($percent%)<br>";
    5887
    5988
Note: See TracChangeset for help on using the changeset viewer.