我有一个活动表,其中包含学生之前加入的活动列表。因此,如果学生是新生,那么该学生就没有活动。
<table align="center" width="1000" border="1" >
<h3>Activity List</h3>
</br>
<tr align="center" style="font-weight:bold" >
<td>ID</td>
<td>Activity</td>
<td>Sem</td>
<td>Session</td>
<td>Achievement</td>
<td>Level</td>
</tr>
<?php do { ?>
<tr align="center">
<td><?php echo $row_Recordset1['student_id']; ?></td>
<td><?php echo $row_Recordset1['activity']; ?></td>
<td><?php echo $row_Recordset1['sem']; ?></td>
<td><?php echo $row_Recordset1['session']; ?></td>
<td><?php echo $row_Recordset1['achievement']; ?></td>
<td><?php echo $row_Recordset1['level']; ?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
如果此表仅为空,我该如何才能使该表显示在屏幕上。顺便说一句,即时通讯使用会话来显示现有记录。
答案 0 :(得分:3)
执行此操作的最佳方法是通过您构建的查询的mysql(i)_fetch_array()
获取阵列,然后检查查询是否包含以下行:
$qry = "SELECT `this` FROM `table`"
while ($result = mysql_fetch_array($qry)) {
if (mysql_num_rows($result) > 0) {
echo "We have rows!";
}
else {
echo "Looks like we haven't got anything here!";
}
}
我希望这会有所帮助。
也可以看一下这里:PHP mysql_num_rows method。
答案 1 :(得分:1)
<?php if(!empty($activity))
{
your msg ..
}
else
{
}
?>
其中empty()
将检查给定变量是否为空
答案 2 :(得分:1)
那就是if语句用于:
if(!count($activities)) {
echo "This student has no activities yet.";
} else {
//display activities
....
}