Total User Statistics

Total User Statistics

by Fazil Mammadov -
Number of replies: 17

Hi all,

I need to generate total registered user statistics in the main page(header or footer). I find in this forum a code like this:

Ger Tielemans:

"Not an answer, but on the front page - in that part (of your theme) header.html - you could insert:

<?php echo " <i><font size=-1 color=green>already<font color=red>$usercount</font>Moodle users on this site</font></i>";?>"

but, it doesnt help it seems like this code doesnt work.

If someone knows any code like this please help.

Thanks a lot.

Fazil.

Average of ratings: -
In reply to Fazil Mammadov

Re: Total User Statistics

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Fazil,

That piece of code is 6 years old! No wonder it no longer works on a recent moodle site... Which version of Moodle are you using?

Joseph

Average of ratings: Useful (1)
In reply to Joseph Rézeau

Re: Total User Statistics

by Fazil Mammadov -

Hi Joseph,

Tnx you for answer. I use 1.9.11

Fazil.

In reply to Fazil Mammadov

Re: Total User Statistics

by Fazil Mammadov -
Nobody can help? sad
In reply to Fazil Mammadov

This forum post has been removed

The content of this forum post has been removed and can no longer be accessed.
In reply to Deleted user

Re: Total User Statistics

by Fazil Mammadov -
Hi Dietmar,

Thank you for your answer. But that code doesnt work, I think here is mistake:

<?php

# get the full directory name of where moodle is installed

$moodle_dir = dirname(dirname(__FILE__));

# include the config.php file
require_once($moodle_dir.'/config.php');

#connect database
$dbconnect=mysql_connect ("$CFG->dbhost", "$CFG->dbuser", "$CFG->dbpass");
mysql_select_db ("$CFG->dbname") or die ("Could not connect!");

#select table 'user'
$dbtable = $CFG->prefix . 'user'; #data selection
$query= 'SELECT * FROM ' . $dbtable;
$result = mysql_query($query);
$rows = mysql_num_rows($result);

#data output
echo 'Moodle users on this site: ' . $rows;

#close connection
mysql_close($dbconnect);

?>

Because the cod seems to end at that bold stage. Itried to correct it but cant when I place this code to header the page doesnt open correctly.

Fazil.

In reply to Fazil Mammadov

This forum post has been removed

The content of this forum post has been removed and can no longer be accessed.
In reply to Deleted user

Re: Total User Statistics

by Fazil Mammadov -
Hi Dietmar,

Thank you very much for help, this code works perfectly. That is absolutely what I want smile

Fazil.

P/S (I dont know why but it counts always +1 user but its not important)

In reply to Fazil Mammadov

This forum post has been removed

The content of this forum post has been removed and can no longer be accessed.
In reply to Deleted user

Re: Total User Statistics

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Dietmar,

Your code for 1.9 gives a PHP warning error (when debug mode is ON):

Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given

Joseph

Average of ratings: Useful (1)
In reply to Joseph Rézeau

This forum post has been removed

The content of this forum post has been removed and can no longer be accessed.
In reply to Deleted user

This forum post has been removed

The content of this forum post has been removed and can no longer be accessed.
In reply to Deleted user

Re: Total User Statistics

by Fazil Mammadov -
Hi Joseph and Dietmar, Thanks both of you for helping. I tried the last code works perfectly on my site. Fazil.
In reply to Deleted user

Re: Total User Statistics

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Dietmar,

Your code does not work. Actually it can be done in 1 line only!

The following will work (tested on moodle 1.9.11 and the stardard theme) Insert the line in blue in your the footer.html file of your current site's theme. Might be slightly different in other themes.

<?php }

echo $loggedinas;
echo $homelink;

echo 'Moodle users on this site:  ' . count_records_sql("SELECT COUNT(*) FROM ".$CFG->prefix . 'user'." WHERE deleted = 0 AND confirmed = 1");

if (!empty($performanceinfo)) {
echo $performanceinfo;
}

Joseph

EDIT.- You had already posted your new code while I was trying out a new solution! Fazil had mentioned he was using moodle 1.9.

In reply to Joseph Rézeau

This forum post has been removed

The content of this forum post has been removed and can no longer be accessed.