donglanying3855 2016-07-10 15:30
浏览 25

从SQL值更改字体样式[关闭]

Here's the thing:

Let's say that I'm creating a database for a football season. There are two columns: player1 and player 2, and a third one wich I will call it "flag". What I need is that if the flag is on "1", the text for the player1 change to bold and the player2 remain normal or viceversa if the flag is 2.

I know it sounds difficult, but that's the best way to put it. The real case is harder to explain.

Cheers!

  • 写回答

1条回答 默认 最新

  • dongyuan9292 2016-07-10 15:47
    关注

    Simple solution is:

    $results = [
        array(
            'team1' => 'TEAM_1',
            'team2' => 'TEAM_2',
            'flag' => 0,
        ),
        array(
            'team1' => 'TEAM_1',
            'team2' => 'TEAM_2',
            'flag' => 1,
        ),
        array(
            'team1' => 'TEAM_1',
            'team2' => 'TEAM_2',
            'flag' => 2,
        ),
    ];
    foreach ($results as $r) {
        if ($r['flag'] == 1) {
            echo '<b>' . $r['team1'] . '</b>';
        } else {
            echo $r['team1'];
        }
        echo ' vs. ';
        if ($r['flag'] == 2) {
            echo '<b>' . $r['team2'] . '</b>';
        } else {
            echo $r['team2'];
        }
    }
    
    评论

报告相同问题?