Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
in Plugins by
edited by

I thought we could do some more statistics for q2a forums...

So what about "questions per day" statistics?

Including a graphical representation / diagram, using PHP or jquery!



We could use open source material from e.g. chiliscripts.com or piwik.org (doing secure code) and do something like that:

statistics example

2 Answers

0 votes
edited by

Alright, I have put  together a tiny script with tablesorting (if you click on the table head). You need to copy the qa-config.php in the same folder:


    require_once( 'qa-config.php' );
    mysql_connect(QA_MYSQL_HOSTNAME, QA_MYSQL_USERNAME, QA_MYSQL_PASSWORD) or die(mysql_error());
    mysql_select_db(QA_MYSQL_DATABASE) or die(mysql_error());
    // userid
    $queryQuestions = mysql_query('SELECT created
                                            FROM `qa_posts`
                                            WHERE `type`="Q"
                                            ORDER BY created DESC
                                            '); // LIMIT 0,10;
    $questions = array();
    $c = 0;
    while($row = mysql_fetch_assoc($queryQuestions)) {
        // take substring, only date from 2013-01-04 15:18:03
        $questions[++$c] .= substr($row['created'],0,10);
    // initial html
    echo '<html>
            <style type="text/css">body{margin:30px 30px 50px 30px;padding:0;font-family:Arial,Tahoma,Verdana,sans-serif;font-size:14px;background:#FFF;color:#121212} h2{color:#006;font-weight:normal;font-size:24px;font-size:160%;padding:0;margin:0} td{border:1px solid #CCC;padding:0 .5em;line-height:25px} tr:hover{background:#ffc} table{background-color:#EEE;margin:30px 0 15px;width:500px;text-align:left;border-collapse:collapse} table thead tr th, table tfoot tr th{background-color:#cfc;border:1px solid #CCC;padding:4px;cursor:pointer;}</style>
            <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
            <script src="https://raw.github.com/Mottie/tablesorter/master/js/jquery.tablesorter.min.js"></script>
            <script type="text/javascript">
                    $(document).ready(function() {
          <h2>Questions per Day</h2>
          <table class="tablesorter"><thead><tr><th>Day</th> <th>Questions</th> </tr></thead>';
    $questionsDays = array_count_values($questions);
    $sum = 0;

    $countDays = 0;
    foreach ($questionsDays as $day => $nrQuestions) {
        echo '<tr><td>'.$day.'</td> <td>'.$nrQuestions.'</td></tr>';
        $sum += $nrQuestions;

    echo '<tr style="background:#FDC;"><td><b>Summed up:</b></td> <td><b>'.$sum.'</b></td></tr>';
    echo '</table>';

    echo '<p style="color:#33F;font-size:20px;">&rarr; Average: ' . round($sum/$countDays,2) . ' questions per day</p>';
    echo '</html></body>';


Enjoy this little "starter" =)




+ showing average in the end:

Exactly! I agree and even trying to create some statics on my free time as well. Will share once done. Good to know from you too..
0 votes

I am proceeding a bit, as soon as I have time, I tidy up the code and release the q2a-statistics plugin.

That's the recent version, graph created by jquery:



Bigger image here.

thanks, i like it. can u post the script for this graph.