0
<marquee behavior="alternate" scrolldelay="1" scrollamount="2">
  <?php do { ?>
     <?php echo $row_Recordset1['Name']; ?>:&nbsp;
     <?php echo $row_Recordset1['Text']; ?>&nbsp;
     &#8226;
  <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</marquee>

<?php mysql_free_result($Recordset1); ?>
4

2 回答 2

1

向用户打印一条友好的消息,而不是NULL

<?php echo (NULL === $row_Recordset1['Text']) ? "No value" : $row_Recordset1['Text']; ?>&nbsp;

如 xil3 所示,您也可以使用此模式(来自文档):

// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop
// Note: If you put extract($row); inside the following loop, you'll
//       then create $userid, $fullname, and $userstatus
while ($row = mysql_fetch_assoc($result)) {
    echo $row["userid"];
    echo $row["fullname"];
    echo $row["userstatus"];
}
于 2010-07-06T21:32:26.783 回答
1

按照您现在编写的方式, $row_Recordset1 第一次进入循环时将为空。

我已经为你重写了:

<marquee behavior="alternate" scrolldelay="1" scrollamount="2">
  <?php while($row_Recordset1 = mysql_fetch_assoc($Recordset1)) { ?>
     <?php echo (($row_Recordset1['Name'] != null) ? $row_Recordset1['Name'] : 'n/a'); ?>:&nbsp;
     <?php echo (($row_Recordset1['Text'] != null) ? $row_Recordset1['Text'] : 'n/a'); ?>&nbsp;
     &#8226;
  <?php } ?>
</marquee>

<?php mysql_free_result($Recordset1); ?>
于 2010-07-06T21:33:46.853 回答