• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

problem with census

kacpersky

Mr. Brightside
Joined
Jan 25, 2009
Messages
499
Reaction score
3
i get this error:
PHP:
Fatal error: Call to a member function query() on a non-object in /var/www/census.php on line 23

line 32:
PHP:
$genderCensus = $db->query('SELECT `sex` AS `key`, COUNT(`id`) AS `value` FROM {players} GROUP BY `sex`')->fetchAll(PDO::FETCH_KEY_PAIR);

what is wrong ?

thanks for help ;)
 
PHP:
<?php
/*
    This file is part of OTSCMS (http://www.otscms.com/) project.

    Copyright (C) 2005 - 2008 Wrzasq ([email protected])

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

// loads census statistics
$genderCensus = $db->query('SELECT `sex` AS `key`, COUNT(`id`) AS `value` FROM {players} GROUP BY `sex`')->fetchAll(PDO::FETCH_KEY_PAIR);
$vocationCensus = $db->query('SELECT `vocation` AS `key`, COUNT(`id`) AS `value` FROM {players} GROUP BY `vocation`')->fetchAll(PDO::FETCH_KEY_PAIR);

// prepares calculation variables
$genderCount = array_sum($genderCensus) / 100;
$vocationCount = array_sum($vocationCensus) / 100;

$vocations = array();

// creates vocations array
foreach( $ots->getVocationsList() as $id => $name)
{
    $vocations[$name] = (int) $vocationCensus[$id] . ' (' . @intval($vocationCensus[$id] / $vocationCount) . '%)';
}

// gender census table
// there could be 0 as a total number of characters
// so we have to controll division by zero error
$gender = $template->createComponent('TableData');
$gender['caption'] = $language['Modules.Statistics.CensusGender'];
$gender['data'] = array($language['main.gender0'] => (int) $genderCensus[0] . ' (' . @intval($genderCensus[0] / $genderCount) . '%)', $language['main.gender1'] => (int) $genderCensus[1] . ' (' . @intval($genderCensus[1] / $genderCount) . '%)');

// vocation census table
$vocation = $template->createComponent('TableData');
$vocation['caption'] = $language['Modules.Statistics.CensusVocation'];
$vocation['data'] = $vocations;

?>
 
i was searching a script for census stats. And i found it.
Yeah now i know that is not a whole script. How i can add it ? What is missing ?
 
Back
Top