如果此行为空,则它将显示另一行

时间:2013-12-03 05:24:02

标签: php mysql row

如果此行为空,我该怎么办呢?它会显示另一行

假设名称行为空白

echo '<td>' . $row['name'] . '</td>';

因此,如果名称行为空白,则会显示echo '<td>' . $row['companyname'] . '</td>';

请帮助我如何解决这个问题 感谢

        echo "<tr>";
        echo '<td>' . $row['buildingname'] . '</td>';
        echo '<td>' . $row['area'] . '</td>';
        echo '<td>' . $row['city'] . '</td>';
        echo '<td>' . $row['flatno'] . '</td>';
        echo '<td>' . $row['name'] . '</td>';
        echo '<td>' . $row['mobileno'] . '</td>';
        echo '<td>' . $row['agreementdates'] . '</td>';
        echo '<td>' . $row['agreementdatee'] . '</td>';    
        echo "</tr>"; 

3 个答案:

答案 0 :(得分:0)

尝试这个我认为这是有效的。

echo '<td>' . empty($row['name']) ? $row['companyname'] : $row['name'] . '</td>';

答案 1 :(得分:0)

尝试

if(empty( $row['name'])){
  $tbl = '<td>' . $row['companyname'] . '</td>';
}else{
   $tbl = '<td>' . $row['name'] . '</td>';
}
echo $tbl;

答案 2 :(得分:0)

试试这个:

echo "<tr>";
 if(!empty($row['buildingname'])) {
    echo '<td>' . $row['buildingname'] . '</td>';
 }
 if(!empty($row['area'])) {
    echo '<td>' . $row['area'] . '</td>';
 }
 if(!empty($row['city'])) {
    echo '<td>' . $row['city'] . '</td>';
 }
 if(!empty($row['flatno'])) {
    echo '<td>' . $row['flatno'] . '</td>';
 }
 if(!empty($row['name'])) {
    echo '<td>' . $row['name'] . '</td>';
 }
 if(!empty($row['mobileno'])) {
    echo '<td>' . $row['mobileno'] . '</td>';
 }
 if(!empty($row['agreementdates'])) {
    echo '<td>' . $row['agreementdates'] . '</td>';
 }
echo "</tr>";