Well if messages.id or thread_id are the same thing then it shouldnt matter, but most likely the thread id is just the parent message id to keep track of threads that are related...i doubt this is your problem
being that this is code from a book, have you verified that your db tables messages or forums have a messages.* field? maybe by making a single simple query for fields that start with messages.?