0

I currently have the following PHP file which is using MySQL and it should return with results from 00:00 to 23:00 (this is a timetable), however it is only returning 01:00 to 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);


?>

Can anyone shed some light

4
  • Is this homework? someone posted something similar... stackoverflow.com/questions/10111956/… Commented Apr 12, 2012 at 0:37
  • What is the value of $yesterdow in your SQL query? Commented Apr 12, 2012 at 0:37
  • Does your database table contain the appropriate values to be returned as your assumption? Commented Apr 12, 2012 at 0:41
  • $yesterdow is just today's day name -1 so it would display Wednesday Commented Apr 12, 2012 at 0:55

1 Answer 1

1

You are overwriting the first result due to the double while loop.

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
        // ...

Also, you may want to use date('Y-m-d') instead of date('l'). I'm not sure what your day column contains, but date('l') returns the name of the day which doesn't discriminate between Tuesday yesterday and Tuesday last week and Tuesday 5 years ago.

You only need one while($row = mysql_fetch_array($result)) instead of two.

Sign up to request clarification or add additional context in comments.

2 Comments

When I remove one of the while loops it result in the content become individually wrapped in <title> </title> and <description> </description> whereas when I use the two while loops it puts all the returned content under one <title><description>ALL OF CONTENT</description></title>
Well I'm not sure what you want the final output to be, but you will probably have to do some reformatting after removing one while loop. All I do know, is that in the code posted, you are losing the first result and the inner while loop is doing all the work. The outer one does nothing except lose one result and print all the inner loop results in one <description> element.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.