Hi i need some help with this error I keep getting. It works fine everywhere else in the script except when I try to call it within this one function.
The function I am calling is: getTotalServers
Error:
Fatal error: Call to a member function prepare() on a non-object in C:\xampp2\htdocs\runeloft\ss_sources\util.php on line 208
Calling in this function:
function display_table($online, $where, $num_servers = null){
global $aaaa, $bbbb;
$num_per_page = 30;
$page = 1;
// how many records per page
$size = 10;
// we get the current page from $_GET
if (isset($_GET['page'])){
$page = (int) $_GET['page'];
}
$aaaa = getTotalServers(1, $num_servers);;
$bbbb = $page;
// create the pagination class
$pagination = new Pagination();
$pagination->setLink("?action=status&page=%s");
$pagination->setPage($page);
$pagination->setSize($size);
$pagination->setTotalRecords($num_servers);
global $g_headers;
$g_headers = array(
'name' => 'Server Name',
'ip' => 'IP',
'port' => 'Port',
'uptime' => 'Uptime',
'online' => 'Status',
);
$start = isset($_GET['start']) ? $_GET['start'] : 0;
mysql_con();
global $g_mysqli;
$start = $g_mysqli->real_escape_string($start);
if(isset($_GET['sort']) && isset($g_headers[$_GET['sort']])){
$order_by = 'ORDER BY `'.$g_mysqli->real_escape_string($_GET['sort']).'` '.(isset($_GET['desc']) ? 'DESC' : 'ASC');
}else{
//default sort
$order_by = 'ORDER BY `uptime` DESC, `time` ASC';
}
//$order_by .= " LIMIT $start, $num_per_page";
$order_by .= " " . $pagination->getLimitSql();
if($start == 0 && $online == 1 && !isset($_GET['sort']))
echoTable('Spons', "`sponsored` != '0'", "ORDER BY `sponsored` DESC, RAND() LIMIT 10");
echoTable('Other', $where, $order_by, $online, $start, $num_per_page, $num_servers);
close_mysql();
}
Called Function:
function getTotalServers($online, $where, $num_servers = null){
$where = "`online` = '$online' AND `sponsored` = '0'";
if($num_servers == null){
global $g_mysqli;
$stmt = $g_mysqli->prepare("SELECT COUNT(*) FROM `servers` WHERE ".$where) or debug($g_mysqli->error);
$stmt->execute();
// bind result variables
$stmt->bind_result($num_servers);
$stmt->fetch();
$stmt->close();
}
return $num_servers;
}
Thanks for any help.