Jump to content

Need help


Lokz

Recommended Posts

Hey everyone! Im getting this error;

 

Fatal error: Cannot redeclare DBLayer::make_players_array() in C:\xampp\htdocs\status\lol.php on line 59

 

Here's my code.. Its probably full of bugs and stuff. If you find a error please explain what I did wrong. Im trying to merge two scripts together to create a online list for a World of Warcraft server.

 

<?php
$lang="en";            // Language ("en" - english, "ru" - russian)
$title="xx";    // Insert the title of your server here
$host="xx";    // HOST for Character database
$user="xx";            // USER for Character database
$password="xx";        // PASS for Character database
$db="xx";        // NAME of Character database
$hostr="xx";    // HOST for Logonserver database
$userr="xx";            // USER for Logonserver database
$passwordr="xx";        // PASS for Logonserver database
$dbr="accounts";        // NAME of Logonserver database
$database_encoding = 'CP1251';     // Set encoding
$img_base = "img/";        // Image dir
$server = "xx";    // Ascent Server Address
$port = "8093";            // Ascent Server Port
$lock_acc=0;            // Lock created account to IP address (1 - on, 0 - off)
$lock_reg=0;            // Registration only one (or more) account from one IP address
                // 0 - not limit, 1 - one acc,  2 - two acc, etc...
class DBLayer
{
    var $link_id;
    var $query_result;
    var $saved_queries = array();
    var $num_queries = 0;

    function DBLayer($db_host, $db_username, $db_password, $db_name)
    {
        $this->link_id = @mysql_connect($db_host, $db_username, $db_password, true);

        if ($this->link_id)
        {
            if (@mysql_select_db($db_name, $this->link_id))
                return $this->link_id;
            else
                error('Unable to select database. MySQL reported: '.mysql_error(), __FILE__, __LINE__);
        }
        else
            error('Unable to connect to MySQL server. MySQL reported: '.mysql_error(), __FILE__, __LINE__);
    }
  function make_players_array(){
    global $host, $user, $password, $db, $database_encoding, $pl_array;
$i=0;
    $ascent_db = new DBLayer($host, $user, $password, $db);
    $ascent_db->query("SET NAMES $database_encoding");
    $query = $ascent_db->query("SELECT * FROM `characters` WHERE `online`='1' ORDER BY `name`");
    while($result = $db->fetch_assoc($query))
    {
        $char_data = ($result['level']);
        $char_gender = ($result['gender']);
        $res_pos=get_zone_name($result['mapId'], $result['positionX'], $result['positionY']);

$pl_array[$i] = Array($result['name'], $result['race'], $result['class'], $char_data, $res_pos, $char_gender);
$i++;
    }
    $ascent_db->close();
    unset($ascent_db);
return $i;
}
function make_players_array(){
    global $host, $user, $password, $db, $database_encoding, $pl_array;
$i=0;
    $ascent_db = new DBLayer($host, $user, $password, $db);
    $ascent_db->query("SET NAMES $database_encoding");
    $query = $ascent_db->query("SELECT * FROM `characters` WHERE `online`='1' ORDER BY `name`");
    while($result = $ascent_db->fetch_assoc($query))
    {
        $char_data = ($result['level']);
        $char_gender = ($result['gender']);
        $res_pos=get_zone_name($result['mapId'], $result['positionX'], $result['positionY']);

$pl_array[$i] = Array($result['name'], $result['race'], $result['class'], $char_data, $res_pos, $char_gender);
$i++;
    }
    $ascent_db->close();
    unset($ascent_db);
return $i;
}
$onlineplayers=make_players_array();
                    
if (!$sort = &$_GET['s']) $sort=0;
if (!$flag = &$_GET['f']) $flag=0;
if ($flag==0)    {    $flag=1; $sort_type='<'; } 
        else    {    $flag=0; $sort_type='>'; }
$link=$_SERVER['PHP_SELF']."?f=".$flag."&s=";

if (!empty($pl_array)) 
    {
    usort($pl_array, create_function('$a, $b', 'if ( $a['.$sort.'] == $b['.$sort.'] ) return 0; if ( $a['.$sort.'] '.$sort_type.' $b['.$sort.'] ) return -1; return 1;'));
    }

$list="";
$i=0;
while ($i < $onlineplayers)
    {
    $name=$pl_array[$i][0];
    $race=$pl_array[$i][1];
    $class=$pl_array[$i][2];
    $res_race = $def['character_race'][$race];
    $res_class = $def['character_class'][$class];
    $lvl=$pl_array[$i][3];
    $loc=$pl_array[$i][4];
    $gender=$pl_array[$i][5];
    $list.= "
                <tr class=txt>
                    <td></td>
                    <td>$name</td>
                    <td align='\center\'><img alt=$res_race src='".$img_base.$race."-$gender.gif' height='18' width='18'></td>
                    <td align='\center\'><img alt=$res_class src='".$img_base."$class.gif' height='18' width='18'></td>
                    <td align='\center\'>$lvl</td>
                    <td >$loc</td>
                </tr>";
    $i++;
    }

if (test_realm())
    {
    $title.=(' ('.$onlineplayers.' '.$text["playerson"].')');
    } else
    {
    $title.=(' '.$text["off"]);
    }
}
?>

 

Thanks  ;D

 

Link to comment
https://forums.phpfreaks.com/topic/94129-need-help/
Share on other sites

The make_players_array() method appears twice within your class. It shouldn't.

 

Thanks for your quick reply.

 

How can I make it only appear once?

 

Basically what I want this script to do

 

- go to the database I have specified

- check the 'accounts' db

- and everyone with online=1 is added up

- Everyone who is online is displayed on a page

 

I know theres proberaly a easier way to do this- but I dont know yet how to :)

 

Cheers!

Link to comment
https://forums.phpfreaks.com/topic/94129-need-help/#findComment-482178
Share on other sites

Actually dont worry,

I removed the replicate but get a;

Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in C:\xampp\htdocs\status\lol.php on line 59

now.

 

 

$lang="en";            // Language ("en" - english, "ru" - russian)
$title="xx";    // Insert the title of your server here
$host="xx";    // HOST for Character database
$user="xx";            // USER for Character database
$password="xx";        // PASS for Character database
$db="xx";        // NAME of Character database
$hostr="xx";    // HOST for Logonserver database
$userr="xx";            // USER for Logonserver database
$passwordr="xx";        // PASS for Logonserver database
$dbr="accounts";        // NAME of Logonserver database
$database_encoding = 'CP1251';     // Set encoding
$img_base = "img/";        // Image dir
$server = "xx";    // Ascent Server Address
$port = "8093";            // Ascent Server Port
$lock_acc=0;            // Lock created account to IP address (1 - on, 0 - off)
$lock_reg=0;            // Registration only one (or more) account from one IP address
                // 0 - not limit, 1 - one acc,  2 - two acc, etc...
class DBLayer
{
    var $link_id;
    var $query_result;
    var $saved_queries = array();
    var $num_queries = 0;

    function DBLayer($db_host, $db_username, $db_password, $db_name)
    {
        $this->link_id = @mysql_connect($db_host, $db_username, $db_password, true);

        if ($this->link_id)
        {
            if (@mysql_select_db($db_name, $this->link_id))
                return $this->link_id;
            else
                error('Unable to select database. MySQL reported: '.mysql_error(), __FILE__, __LINE__);
        }
        else
            error('Unable to connect to MySQL server. MySQL reported: '.mysql_error(), __FILE__, __LINE__);
    }
  function make_players_array(){
    global $host, $user, $password, $db, $database_encoding, $pl_array;
$i=0;
    $ascent_db = new DBLayer($host, $user, $password, $db);
    $ascent_db->query("SET NAMES $database_encoding");
    $query = $ascent_db->query("SELECT * FROM `characters` WHERE `online`='1' ORDER BY `name`");
    while($result = $db->fetch_assoc($query))
    {
        $char_data = ($result['level']);
        $char_gender = ($result['gender']);
        $res_pos=get_zone_name($result['mapId'], $result['positionX'], $result['positionY']);

$pl_array[$i] = Array($result['name'], $result['race'], $result['class'], $char_data, $res_pos, $char_gender);
$i++;
    }
    $ascent_db->close();
    unset($ascent_db);
return $i;
}

$onlineplayers=make_players_array();
                    
if (!$sort = &$_GET['s']) $sort=0;
if (!$flag = &$_GET['f']) $flag=0;
if ($flag==0)    {    $flag=1; $sort_type='<'; } 
        else    {    $flag=0; $sort_type='>'; }
$link=$_SERVER['PHP_SELF']."?f=".$flag."&s=";

if (!empty($pl_array)) 
    {
    usort($pl_array, create_function('$a, $b', 'if ( $a['.$sort.'] == $b['.$sort.'] ) return 0; if ( $a['.$sort.'] '.$sort_type.' $b['.$sort.'] ) return -1; return 1;'));
    }

$list="";
$i=0;
while ($i < $onlineplayers)
    {
    $name=$pl_array[$i][0];
    $race=$pl_array[$i][1];
    $class=$pl_array[$i][2];
    $res_race = $def['character_race'][$race];
    $res_class = $def['character_class'][$class];
    $lvl=$pl_array[$i][3];
    $loc=$pl_array[$i][4];
    $gender=$pl_array[$i][5];
    $list.= "
                <tr class=txt>
                    <td></td>
                    <td>$name</td>
                    <td align='\center\'><img alt=$res_race src='".$img_base.$race."-$gender.gif' height='18' width='18'></td>
                    <td align='\center\'><img alt=$res_class src='".$img_base."$class.gif' height='18' width='18'></td>
                    <td align='\center\'>$lvl</td>
                    <td >$loc</td>
                </tr>";
    $i++;
    }

if (test_realm())
    {
    $title.=(' ('.$onlineplayers.' '.$text["playerson"].')');
    } else
    {
    $title.=(' '.$text["off"]);
    }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/94129-need-help/#findComment-482180
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.