2010-07-06 46 views
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); ?> 
+0

不是一个真正的问题?怎么会这样?正确的NULL值处理似乎很真实... – EFraim 2010-07-06 21:34:30

+3

[元素](http://reference.sitepoint.com/html/marquee)是非标准的,不应使用。移动文本是一种可访问性障碍,并且直截了当地说:移动文本只是简单的恼人的垃圾。 – Gordon 2010-07-06 21:34:50

+0

@EFraim我相信他们指的是$ row_Recordset1 ['Text'],在这种情况下,如果它是NULL,它最终可能只打印一个名称而没有后续文本。问题是关于怎么做,然后我猜... – 2010-07-06 21:36:37

回答

1

打印一个友好的信息给用户,而不是NULL

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

由于xil3所示,您也可以使用此模式(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"]; 
} 
+0

'($ row_Recordset1 ['Text']!='NULL')'这是错的!这是正确的:'($ row_Recordset1 ['Text']!== NULL)'见:http://php.net/manual/en/language.operators.comparison.php – Dolph 2010-07-06 21:40:38

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); ?> 
+0

对不起,我的意思是在一些文本字段为空:) – mattes 2010-07-06 21:47:29

+0

我刚更新了答案。 – xil3 2010-07-06 21:56:25