• 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!

[PHP] Display deaths?

ond

Veteran OT User
Joined
Mar 24, 2008
Messages
2,775
Solutions
25
Reaction score
483
Location
Sweden
Hello, I have an issue with my website. If, let's say, you die 3 times, then the last death will only be shown.

= Only show one death when you search on the website, for that character. My database store all deaths, so it must be the website's scripts & functions that need to be edited.

Here is

htdocs/class/player.php:


PHP:
    private function load_deaths() {
        if(empty($this->attrs['id'])) throw new PlayerNotLoadedException();
		if($this->sql->isTable('player_deaths')) {
            $query = "SELECT * FROM `player_deaths` WHERE (`player_id` = '".$this->sql->quote($this->attrs['id'])."') ORDER BY time DESC LIMIT 10";
            $this->sql->myQuery($query);
            $i = 0;
            while($a = $this->sql->fetch_array()) {
                $killer = new Player();
                try {
                    $killer->find($a['lasthit_killer']);
                    $this->deaths[$i]['killer_name'] = $killer->attrs['name'];
                    $this->deaths[$i]['killer_id'] = $killer->attrs['id'];
                } catch(PlayerNotFoundException $e) {
                    try {
                        $killer->load($death['lasthit_killer']);
                        $this->deaths[$i]['killer_name'] = $killer->attrs['name'];
                        $this->deaths[$i]['killer_id'] = $killer->attrs['id'];
                    } catch(PlayerNotFoundException $e) {
                        $this->deaths[$i]['killer_name'] = $a['lasthit_killer'];
                        $this->deaths[$i]['killer_id'] = null;
                    }
                }

                $this->deaths[$i]['victim_level'] = $a['level'];
                $this->deaths[$i]['date'] = $a['time'];
                $i++;
            }
        } else throw new DatabaseException('Deaths data not found in database or it is not compatible.');

        return true;
    }

htdocs/characters.php:

PHP:
            if ($cfg['show_deathlist']) {
                if ($player->deaths) {
                    echo '<b>Latest Deaths</b><br/>';
                    $prevdate = 0;
                    foreach ($player->deaths as $death) {
                        if ($death['killer_id'])
                            $name = '<a href="characters.php?player_id='.$death['killer_id'].'">'.$death['killer_name'].'</a>';
                        else
                            $name = $death['killer_name'];
                        if($prevdate == $death['date'])
                            echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;and by '.$name.'<br/>';
                        else
                            echo '<i>'.date("jS F Y H:i:s",$death['date']).'</i> Killed at level '.$death['victim_level'].' by '.$name.'<br/>';
                        $prevdate = $death['date'];
                    }
                }
            }
        } catch(PlayerNotFoundException $e) {
            echo 'Player not found';
        } catch(PlayerException $e) {}

If I were unclear what I need help with, just post here and I'll try to explain even better. I would be very glad if someone could help me with this, I think it can help more than me.

Thanks for now!
 
put it:
PHP:
echo count($player->deaths);exit;
after
PHP:
 if ($player->deaths) {
and tell me what number is being shown.
 
Solved it, still it got solved in a "none-proffesional programing way" there is a big bug in nicaw (no harmful bug)
 
Back
Top Bottom