php – Why my function don't see other options like red/green-ThrowExceptions

Exception or error:
  $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;
                        }

That line don’t work well:

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

All the time characters are “online” i mean GREEN
What is wrong?

How to solve:

try this:

$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;
}

Even this is a rough implementation. You should try to query your player online list first. After this check in the loop. I can provide you an example if you want.

Leave a Reply

Your email address will not be published. Required fields are marked *