Total User Statistics

Total User Statistics

deur Fazil Mammadov -
Getal antwoorde: 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.

Gemiddeld van beoordelings: -
In antwoord op Fazil Mammadov

Re: Total User Statistics

deur Joseph Rézeau -
Prentjie van Core developers Prentjie van Particularly helpful Moodlers Prentjie van Plugin developers Prentjie van Testers Prentjie van 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

Gemiddeld van beoordelings:Useful (1)
In antwoord op Joseph Rézeau

Re: Total User Statistics

deur Fazil Mammadov -

Hi Joseph,

Tnx you for answer. I use 1.9.11

Fazil.

Gemiddeld van beoordelings: -
In antwoord op Fazil Mammadov

Re: Total User Statistics

deur Fazil Mammadov -
Nobody can help? hartseer
Gemiddeld van beoordelings: -
In antwoord op Fazil Mammadov

Hierdie forumplasing is verwyder

Die inhoud van hierdie forumplasing is verwyder en is nie meer toeganklik nie.
In antwoord op Skrap gebruiker

Re: Total User Statistics

deur 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.

Gemiddeld van beoordelings: -
In antwoord op Fazil Mammadov

Hierdie forumplasing is verwyder

Die inhoud van hierdie forumplasing is verwyder en is nie meer toeganklik nie.
In antwoord op Skrap gebruiker

Re: Total User Statistics

deur Fazil Mammadov -
Hi Dietmar,

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

Fazil.

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

Gemiddeld van beoordelings: -
In antwoord op Fazil Mammadov

Hierdie forumplasing is verwyder

Die inhoud van hierdie forumplasing is verwyder en is nie meer toeganklik nie.
In antwoord op Skrap gebruiker

Re: Total User Statistics

deur Joseph Rézeau -
Prentjie van Core developers Prentjie van Particularly helpful Moodlers Prentjie van Plugin developers Prentjie van Testers Prentjie van 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

Gemiddeld van beoordelings:Useful (1)
In antwoord op Joseph Rézeau

Hierdie forumplasing is verwyder

Die inhoud van hierdie forumplasing is verwyder en is nie meer toeganklik nie.
In antwoord op Skrap gebruiker

Hierdie forumplasing is verwyder

Die inhoud van hierdie forumplasing is verwyder en is nie meer toeganklik nie.
In antwoord op Skrap gebruiker

Re: Total User Statistics

deur Fazil Mammadov -
Hi Joseph and Dietmar, Thanks both of you for helping. I tried the last code works perfectly on my site. Fazil.
Gemiddeld van beoordelings: -
In antwoord op Skrap gebruiker

Re: Total User Statistics

deur Joseph Rézeau -
Prentjie van Core developers Prentjie van Particularly helpful Moodlers Prentjie van Plugin developers Prentjie van Testers Prentjie van 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.

Gemiddeld van beoordelings: -
In antwoord op Joseph Rézeau

Hierdie forumplasing is verwyder

Die inhoud van hierdie forumplasing is verwyder en is nie meer toeganklik nie.