Reputation: 1
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:
"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"
I use MRBS 1.4.11, Apache/2.2.16 (Debian), MySQL client version: 5.1.66. I found this theme: display todays bookings from mysql mrbs calendar also checked some infos on http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_timestamp 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:)
$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->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 = "<TABLE align=center BORDER=1 CELLPADDING=5>\n";
$booking_block .= "<tr><td colspan=".$n_cols.">";
$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 .= ")</td></tr>\n";
$booking_block .= "<tr><td align=right>".$startYear."</td>\n";
while ($rooms = mysql_fetch_array($rooms_result, MYSQL_ASSOC))
{
$booking_block .= "<td>";
$booking_block .= $rooms['room_name'];
$booking_block .= "</td>";
}
$booking_block .= "</tr>\n";
for ($day_number = 0; $day_number <= 6; $day_number++)
{
$booking_block .= "<tr>\n";
$booking_block .= "<td align=right valign=top>";
$endOfDay = $theTimestamp + ONE_DAY;
$theDateArray = getdate($theTimestamp);
if ($theDateArray['year'] != $startYear)
{
$startYear = $theDateArray['year'];
$booking_block .= $startYear."<br>";
}
$booking_block .= date("D d M", $theTimestamp)."</td>\n";
for ($room_number = 1; $room_number <= $n_rooms; $room_number++)
{
$get_bookings = "select *
from $bookings
where start_time >= $theTimestamp
and start_time <= $endOfDay
and room_id = $room_number
order by start_time
"
;
$bookings_result = mysql_query($get_bookings) or die(mysql_error());
$booking_block .= "<td valign=top>";
if (mysql_num_rows($bookings_result) > 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 .= "<br>\n";
}
}
else
{
$booking_block .= "<br>";
}
$booking_block .= "</td>";
}
$booking_block .= "</tr>\n";
$theTimestamp = $theTimestamp + ONE_DAY;
}
$booking_block .= "<tr><td colspan=".$n_cols." align=right>";
$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 .= "</table>\n";
Upvotes: 0
Views: 999
Reputation: 360782
MySQL's error snippets start at the point of the query AFTER where the error occurred. Since you're getting order by ...
in the error output, that means the error was right before that point, which probably means $bookings
is undefined, and your query looks like
SELECT timestamp
FROM
ORDER BY timestamp DESC
Note the lack of a table name. an echo $get_entries
will confirm that.
Upvotes: 2