$position = 1;
                        foreach($SQL->query('SELECT players.name, players.level, players.id, players_online.player_id FROM players,players_online ORDER BY players.level DESC LIMIT 8') as $i => $data)
                        {
                        echo  $position .
'  <a style="font-weight:bold;text-decoration:none;" href="?subtopic=characters&name='.
urlencode($data['name']).
'">'.
($data['players_online.player_id'] == $data['players.id'] ? "<font color=\"green\">". htmlspecialchars($data['name'])."</font>" : "<font color=\"red\">".htmlspecialchars($data['name'])."</font>").
'</a> ( ' .
$data['level'] .
' )<br>';
                        $position = $position+1;
                        }

Baris itu tidak berfungsi dengan baik:

$data['players_online.player_id'] == $data['players.id'] ? "<font color=\"green\">". htmlspecialchars($data['name'])."</font>" : "<font color=\"red\">".htmlspecialchars($data['name'])."</font>").

Semua karakter waktu "online" maksud saya HIJAU Apa yang salah?

php
0
Bon1facy 17 Maret 2020, 19:54

1 menjawab

Jawaban Terbaik

Coba ini:

$position = 1;
$query = 'SELECT players.name, players.level, players.id, players.id IN (SELECT players_online.player_id FROM players_online) AS online FROM players ORDER BY layers.level DESC LIMIT 8';
$result = $SQL->query($query);
foreach($result as $i => $data)
{
    echo  $position .'  <a style="font-weight:bold;text-decoration:none;" href="?subtopic=characters&name='.urlencode($data['name']).'">'.
        ($data['online'] ? "<font color=\"green\">". htmlspecialchars($data['name'])."</font>" : "<font color=\"red\">".htmlspecialchars($data['name'])."</font>").'</a> ( ' .$data['level'] .' )<br>';
    $position = $position+1;
}

Bahkan ini adalah implementasi yang kasar. Anda harus mencoba untuk menanyakan daftar pemain online Anda terlebih dahulu. Setelah ini, periksa dalam loop. Saya bisa memberi Anda contoh jika Anda mau.

0
Peter G. 17 Maret 2020, 17:18