如果我的while循环中的变量为空,则回显0而不是空

Mau*_*ice 0 php string variables

我有以下循环:

    while($row = mysql_fetch_assoc($result)) {
    <some code>
     if ($user)
                echo '<li><a href="mahjong.php?layout='.$row['LayoutName'].'"><img src="images/layouts/'. $row['LayoutName'].'.png" alt="" /> <img src="images/'. $row['Stars'].'.png" alt="" /></a>
                        <div class="info">
                            <h2>'.$row['LayoutName'].'</h2>
                            <p>'.$row['LayoutTiles'].' Tiles, '.$row['LayoutLayers'].' Layers</p>
                            <hr size=2 color="white"> 
                            <p>Score: '.$row['Score'].'</p> 
                            <p>Time:&nbsp;&nbsp;'.$row['Time'].'</p>
                        </div>
                      </li>';
            else 
    <some more code> 
}
Run Code Online (Sandbox Code Playgroud)

这个while循环完美地运行,但有时一些变量没有数据.这是正确的,因为数据库中没有简单的.如果发生这种情况,它什么都不显示 我想要它,如果变量为空,它回显0.

示例$row['Score']=空 - > 0

谢谢,

ps有可能$row['Time']有一个值而$row['Score']不是!!

Thi*_*ter 5

在最近的PHP版本中,您可以使用$row['Score'] ?: 0等.