diff --git a/include/class.thread.php b/include/class.thread.php index 8f108d70503ef5fb4f65a667b02c5da964e4da2f..d5442eb3dcd25f4a571ce529a035f534c4a3b0d2 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -783,15 +783,16 @@ class Message extends ThreadEntry { )?$m:null; } - function lastByExtTicketId($ticketId) { - $sql = 'SELECT thread.id FROM '.TICKET_THREAD_TABLE - .' thread JOIN '.TICKET_TABLE.' ticket ON (ticket.ticket_id = thread.ticket_id) - WHERE thread_type=\'M\' AND ticket.ticketID = '.db_input($ticketId) + function lastByTicketId($ticketId) { + + $sql=' SELECT thread.id FROM '.TICKET_THREAD_TABLE.' thread ' + .' WHERE thread_type=\'M\' AND thread.ticket_id = '.db_input($ticketId) .' ORDER BY thread.id DESC LIMIT 1'; - if (($res = db_query($sql)) && (list($id) = db_fetch_row($res))) + + if (($res = db_query($sql)) && ($id = db_result($res))) return Message::lookup($id); - else - return null; + + return null; } }