How to change the color of 1 string

Asked

Viewed 63 times

0

Hello, so I want to do 1 player rank on my site, and I put the position of each player there, but it has 1 however, each position has its color, and in mysql is only the title name, as I do for it to pick 1 name and change the color. Example: Director, he will leave <td style="color: orange;">Diretor</td>

    public function RankSkyWars()
{
    $stmt = $this->pdo->prepare("SELECT * FROM tskywars INNER JOIN tcommons ON tskywars.id = tcommons.id INNER JOIN permusers ON tcommons.id = permusers.id ORDER BY `solowins` DESC LIMIT 100");
    $stmt->execute();
    if($stmt->rowCount() == 0) { return ""; }
    $fetch = $stmt->fetchAll(\PDO::FETCH_OBJ);
    $return = "";
    foreach ($fetch as $rs)
    {
        $deaths = "".number_format($rs->solodeaths, 0, ',', '.');
        $wins = "".number_format($rs->solowins, 0, ',', '.');
        $kills = "".number_format($rs->solokills, 0, ',', '.');
        $coins = "".number_format($rs->coins, 0, ',', '.');
        $return .= "<tr>
                        <td style=\"text-align: left;\" class=\"leaderboard-username\"><img src=\"https://minotar.net/helm/{$rs->name}/32.png\"> {$rs->name}</td>
                        <td style=\"text-align: left;\" class=\"leaderboard-stat\" id=\"cargo\">{$rs->groups}</td>
                        <td style=\"text-align: left;\" class=\"leaderboard-stat\">$wins</td>
                        <td style=\"text-align: left;\" class=\"leaderboard-stat\">$kills</td>
                        <td style=\"text-align: left;\" class=\"leaderboard-stat\">$deaths</td>
                        <td style=\"text-align: left;\" class=\"leaderboard-stat\">$coins</td>
                    </tr>";
    }
    return $return;
}

1 answer

0


You can do so (commented code):

    $color = "color: ";

    switch($rs->groups){
        case "Diretor": $color."orange;"; break; // se for diretor
        case "Ajudante": $color."yellow;"; break; // se for ajudante
        default : $color."black;";
    }

    // insere a cor
    $return .= "<tr>
                    <td style=\"text-align: left;\" class=\"leaderboard-username\"><img src=\"https://minotar.net/helm/{$rs->name}/32.png\"> {$rs->name}</td>
                    <td style=\"text-align: left;$color\" class=\"leaderboard-stat\" id=\"cargo\">{$rs->groups}</td> 
                    <td style=\"text-align: left;\" class=\"leaderboard-stat\">$wins</td>
                    <td style=\"text-align: left;\" class=\"leaderboard-stat\">$kills</td>
                    <td style=\"text-align: left;\" class=\"leaderboard-stat\">$deaths</td>
                    <td style=\"text-align: left;\" class=\"leaderboard-stat\">$coins</td>
                </tr>";

Browser other questions tagged

You are not signed in. Login or sign up in order to post.