Total User Statistics

Total User Statistics

Fazil Mammadov -
回帖数: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.

回复Fazil Mammadov

Re: Total User Statistics

Joseph Rézeau -
Core developers的头像 Particularly helpful Moodlers的头像 Plugin developers的头像 Testers的头像 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

回复Joseph Rézeau

Re: Total User Statistics

Fazil Mammadov -

Hi Joseph,

Tnx you for answer. I use 1.9.11

Fazil.

回复Fazil Mammadov

Re: Total User Statistics

Fazil Mammadov -
Nobody can help? 伤心
回复Fazil Mammadov

本讨论区帖子已移除

本讨论区帖子的内容已移除,无法再访问。
回复删除的用户

Re: Total User Statistics

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.

回复Fazil Mammadov

本讨论区帖子已移除

本讨论区帖子的内容已移除,无法再访问。
回复删除的用户

Re: Total User Statistics

Fazil Mammadov -
Hi Dietmar,

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

Fazil.

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

回复Fazil Mammadov

本讨论区帖子已移除

本讨论区帖子的内容已移除,无法再访问。
回复删除的用户

Re: Total User Statistics

Joseph Rézeau -
Core developers的头像 Particularly helpful Moodlers的头像 Plugin developers的头像 Testers的头像 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

回复Joseph Rézeau

本讨论区帖子已移除

本讨论区帖子的内容已移除,无法再访问。
回复删除的用户

本讨论区帖子已移除

本讨论区帖子的内容已移除,无法再访问。
回复删除的用户

Re: Total User Statistics

Fazil Mammadov -
Hi Joseph and Dietmar, Thanks both of you for helping. I tried the last code works perfectly on my site. Fazil.
回复删除的用户

Re: Total User Statistics

Joseph Rézeau -
Core developers的头像 Particularly helpful Moodlers的头像 Plugin developers的头像 Testers的头像 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.

回复Joseph Rézeau

本讨论区帖子已移除

本讨论区帖子的内容已移除,无法再访问。