0

这是我的代码

$Qemaster="select * from emaster where `branch`='$bid' and `department`='$did' and `status`!='L'";
$Remaster=mysql_query($Qemaster);
while($Rowemaster=mysql_fetch_array($Remaster)){
    $empcode=$Rowemaster[id];
    $name=$Rowemaster[name];
    $Tleave=0;

echo "<tr>";
echo "<td rowspan='2'>".$name."</td>";
echo "<td>Leave</td>";

$Qlp="select `leave` from lpsummary where ((`month` IN(04,05,06,07,08,09,10,11,12) and `year`='$year') or (`month` IN(01,02,03) and `year`='$Nyear')) and `empcode`='$empcode'";
$Rlp=mysql_query($Qlp);
while($Rowlp=mysql_fetch_array($Rlp)){  

$leave=$Rowlp['leave'];
$Tleave=$Tleave+$leave;

echo "<td>".$leave."</td>";
}
echo "<td><font color='red'>".$Tleave."</font></td>";
echo "<tr><td>Percentage</td>";
}

我的桌子是

------------------------------------------
| name | apr-12 | may-12 | jun-12 | jul-12 |
|------|--------|--------|--------|--------|  
|Kumar | 2      |    1   |    0   | 3      |
|Rajan | 4      |    0   |    2   |        |
|      |        |        |        |        |
|------------------------------------------ 

这里以 Rajan 为名,在 jun-12 中没有数据,但 jul-12 的值为 2...即)表 lpsummary 中的空行......如果有空行,我想将其替换为 ' -'......我怎么能通过我的代码做到这一点......

4

1 回答 1

0

在您的 while 循环中,您需要设置一个条件来检查是否返回了 null from。

while($Rowlp=mysql_fetch_array($Rlp)){  
    if (is_null($Rowlp['leave'])) {
        $leave = '-';
    } else {
        $leave=$Rowlp['leave'];
        $Tleave=$Tleave+$leave;
    }

    echo "<td>".$leave."</td>";
}
于 2013-06-14T13:15:05.540 回答