title: MySQL error: 'order by timestamp desc limit 1' at line 5
body: <p>I am trying couple of days run script "showcalendar.php" from Rowland Carson in MRBS calendar. I went through some errors with database, but now stuck by these:</p>
  
  <blockquote>
    <p>"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order by timestamp desc limit 1' at line 5"</p>
  </blockquote>
  
  <p>I use MRBS 1.4.11, Apache/2.2.16 (Debian), MySQL client version: 5.1.66.
  I found this theme: <a href="https://stackoverflow.com/questions/9795360/display-todays-bookings-from-mysql-mrbs-calendar">display todays bookings from mysql mrbs calendar</a>
  also checked some infos on <a href="http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_timestamp" rel="nofollow noreferrer">http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_timestamp</a> and made gogolresearch
  but no progress. Please could You help me or give me advice for right direction?
  Thank You very much for Your time and energy:)</p>
  
  <pre><code>$conn = mysql_connect($mysql_host, $mysql_user, $mysql_pass)
  
  or die(mysql_error());
  
  mysql_select_db("mrbs", $conn)  or die(mysql_error());
  
  
  
  $get_entries = "select timestamp
  
  from $bookings
  
  order by timestamp desc
  
  limit 1
  
  "
  
  ;
  
  $entries_result = mysql_query($get_entries) or die(mysql_error());
  
  $data_row = mysql_fetch_object($entries_result);
  
  $last_changed = $data_row-&gt;timestamp;
  
  
  
  $get_rooms = "select *
  
  from $rooms
  
  order by id
  
  "
  
  ;
  
  $rooms_result = mysql_query($get_rooms) or die(mysql_error());
  
  $n_rooms = mysql_num_rows($rooms_result);
  
  $n_cols = $n_rooms + 1;
  
  
  
  $booking_block = "&lt;TABLE align=center BORDER=1 CELLPADDING=5&gt;\n";
  
  $booking_block .= "&lt;tr&gt;&lt;td colspan=".$n_cols."&gt;";
  
  $booking_block .= "Room bookings for week beginning ";
  
  $booking_block .= $startingDateArray['mday']." ";
  
  $booking_block .= $startingDateArray['month']." ";
  
  $booking_block .= $startingDateArray['year']." ";
  
  $booking_block .= "(Last change to any booking was made ";
  
  $booking_block .= $last_changed;
  
  $booking_block .= ")&lt;/td&gt;&lt;/tr&gt;\n";
  
  $booking_block .= "&lt;tr&gt;&lt;td align=right&gt;".$startYear."&lt;/td&gt;\n";
  
  
  
  while ($rooms = mysql_fetch_array($rooms_result, MYSQL_ASSOC))
  
  {
  
  $booking_block .= "&lt;td&gt;";
  
  $booking_block .= $rooms['room_name'];
  
  $booking_block .= "&lt;/td&gt;";
  
  }
  
  $booking_block .= "&lt;/tr&gt;\n";
  
  
  
  for ($day_number = 0; $day_number &lt;= 6; $day_number++)
  
  {
  
  $booking_block .= "&lt;tr&gt;\n";
  
  $booking_block .= "&lt;td align=right valign=top&gt;";
  
  $endOfDay = $theTimestamp + ONE_DAY;
  
  $theDateArray = getdate($theTimestamp);
  
  if ($theDateArray['year'] != $startYear)
  
  {
  
      $startYear = $theDateArray['year'];
  
      $booking_block .= $startYear."&lt;br&gt;";
  
  }
  
  $booking_block .= date("D d M", $theTimestamp)."&lt;/td&gt;\n";
  
  
  
  for ($room_number = 1; $room_number &lt;= $n_rooms; $room_number++)
  
  {
  
      $get_bookings = "select *
  
          from $bookings
  
          where start_time &gt;= $theTimestamp
  
          and start_time &lt;= $endOfDay
  
          and room_id = $room_number
  
          order by start_time
  
          "
  
          ;
  
      $bookings_result = mysql_query($get_bookings) or die(mysql_error());
  
      $booking_block .= "&lt;td valign=top&gt;";
  
      if (mysql_num_rows($bookings_result) &gt; 0)
  
      {
  
          while ($booking_entry = mysql_fetch_array($bookings_result, MYSQL_ASSOC))
  
          {
  
              $booking_block .= date("H:i", $booking_entry['start_time']);
  
              $booking_block .= "-";
  
              $booking_block .= date("H:i", $booking_entry['end_time']);
  
              $booking_block .= " ";
  
              $booking_block .= $booking_entry['name'];
  
              $booking_block .= "&lt;br&gt;\n";
  
          }
  
      }
  
      else
  
      {
  
          $booking_block .= "&lt;br&gt;";
  
      }
  
      $booking_block .= "&lt;/td&gt;";
  
  }
  
  $booking_block .= "&lt;/tr&gt;\n";
  
  $theTimestamp = $theTimestamp + ONE_DAY;
  
  }
  
  
  
  $booking_block .= "&lt;tr&gt;&lt;td colspan=".$n_cols." align=right&gt;";
  
  $booking_block .= "This web page rendered at ";
  
  $booking_block .= sprintf("%02d:%02d:%02d",
  
                          $nowArray['hours'],
  
                          $nowArray['minutes'],
  
                          $nowArray['seconds']);
  
  $booking_block .= " on ";
  
  $booking_block .= $nowArray['mday']." ";
  
  $booking_block .= $nowArray['month']." ";
  
  $booking_block .= $nowArray['year']." ";
  
  
  
  $booking_block .= "&lt;/table&gt;\n";
  </code></pre>