PHP隐藏表行中的链接名称

时间:2013-08-18 15:23:53

标签: php html-table

以下代码通常显示2列,其中包含链接名称Engagement reportPersonal report

有些情况下,第二个超链接字段$ccP为空,我希望该单元格也显示为空,而不是Personal report

请帮助实现这一目标。

while($row = mysql_fetch_array($login)){
  $Report=$row['ReportName'];
  $cc=$row['LinkEngagement'];
  $ccP=$row['LinkPersonal'];

   print "<tr class='alt'>
    <td align='Left'>$Report</td>
    <td align='Center'><a href='$cc' style='cursor:pointer'      >Engagement report &nbsp;</a></td>
    <td align='Center'><a href='$ccP' style='cursor:pointer'      >Personal report  &nbsp;</a></td>

    </tr>";
  }
  print "</table>";

2 个答案:

答案 0 :(得分:0)

检查$ccP是否分配了某些内容,并且仅在打印时才打印。

if($ccP){
    print "<td align='Center'><a href='$ccP' style='cursor:pointer'      >Personal report  &nbsp;</a></td>";
}

答案 1 :(得分:0)

while($row = mysql_fetch_array($login)){
  $Report=$row['ReportName'];
  $cc=$row['LinkEngagement'];
  $ccP=$row['LinkPersonal'];
  $ccPLink=(empty($ccp)) ? "" : $ccp ;

  print "<tr class='alt'>
           <td align='Left'>$Report</td>
           <td align='Center'><a href='$cc' style='cursor:pointer'>Engagement report &nbsp;</a></td>
           <td align='Center'><a href='$ccP' style='cursor:pointer'>$ccpLink  &nbsp;</a></td>
         </tr>";
}