当 Text = NULL 时我该怎么办?

发布于 2024-09-08 09:33:30 字数 396 浏览 10 评论 0原文

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

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

<?php mysql_free_result($Recordset1); ?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

水溶 2024-09-15 09:33:30

向用户打印友好消息而不是 NULL

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

如 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"];
}

Print a friendly message to the user instead of NULL:

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

As xil3 illustrates, you can also use this pattern (from the docs):

// 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"];
}
执手闯天涯 2024-09-15 09:33:30

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

我已经为你重写了:

<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'); ?>: 
     <?php echo (($row_Recordset1['Text'] != null) ? $row_Recordset1['Text'] : 'n/a'); ?> 
     •
  <?php } ?>
</marquee>

<?php mysql_free_result($Recordset1); ?>

The way you have it written right now, $row_Recordset1 will be null the first time it goes into the loop.

I've rewritten it for you:

<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'); ?>: 
     <?php echo (($row_Recordset1['Text'] != null) ? $row_Recordset1['Text'] : 'n/a'); ?> 
     •
  <?php } ?>
</marquee>

<?php mysql_free_result($Recordset1); ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文