0

我目前有以下使用 MySQL 的 PHP 文件,它应该返回 00:00 到 23:00 的结果(这是一个时间表),但是它只返回 01:00 到 23:00:

<?PHP
 include("../panel/config.php");
 #// Timetable Clearup Variabls

$yesterday = strtotime('yesterday');
$yesterdow = date('l',$yesterday);
$order = "SELECT * FROM timetable WHERE day = '$yesterdow' ORDER BY time LIMIT 0 , 30";
$result = mysql_query($order);
$yesterdayd = date('F jS, Y', time()-86400);

    //SET XML HEADER
    header('Content-type: text/xml');

    //CONSTRUCT RSS FEED HEADERS
    $output = '<rss version="2.0">';
    $output .= '<channel>';
    $output .= "<title>Timetable - {$yesterdayd} </title>";
    $output .= '<description>Timetable.</description>';
        $output .= '<link>http://www.site.com</link>';
     while ($row = mysql_fetch_array($result)) {
    //BODY OF RSS FEED

   $output .= "<item><title>Timetable - {$yesterdayd}</title>
   <description>";
while ($row=mysql_fetch_array($result))
{
        $rowset[] = $row;
  //BODY OF RSS FEED
  $output .= htmlspecialchars($row['time']) . " " . htmlspecialchars($row['username']) . "<br/>";
}
$output .= '</description></item> ';
 }
    //CLOSE RSS FEED
   $output .= '</channel>';
   $output .= '</rss>';

    //SEND COMPLETE RSS FEED TO BROWSER
$filename = "timetable.xml";

                if (!$handle = fopen($filename, 'w')) {
            echo "Cannot open file ($filename)";
            exit;
            }

            // Write $somecontent to our opened file.
            if (fwrite($handle, $output) === FALSE) {
            echo "Cannot write to file ($filename)";
            exit;
            }

            if (fwrite($handle, $total) === FALSE) {
            echo "Cannot write to file ($filename)";
            exit;
            }

            echo "Success, wrote {$content}{$total} to file ($filename)";

            fclose($handle);


?>

谁能解释一下

4

1 回答 1

1

由于双 while 循环,您正在覆盖第一个结果。

while ($row = mysql_fetch_array($result)) {
    //BODY OF RSS FEED

    $output .= "<item><title>Timetable - {$yesterdayd}</title><description>";
    while ($row=mysql_fetch_array($result))
    {
        // First $row result is now overwritten before you used it
        // ...

此外,您可能希望使用date('Y-m-d')而不是date('l'). 我不确定您的日期列包含什么,但date('l')返回的日期名称不区分昨天的星期二和上周的星期二以及 5 年前的星期二。

你只需要一个while($row = mysql_fetch_array($result))而不是两个。

于 2012-04-12T00:41:48.970 回答