% Option Explicit Dim sql, username, rsMessages, rsMessageRead, newcount username = Request.Cookies("username") if username = "" then Response.Redirect("index.asp?page=inbox.asp") end if %> <% sql = "SELECT Messages.*, icon FROM Users INNER JOIN Messages ON Users.username = Messages.sentfrom WHERE sendto = '" & username & "' ORDER BY datesent DESC" Set rsMessages = Server.CreateObject("ADODB.Recordset") rsMessages.Open sql, conn, 3, 3 'Count the amount of new messages newcount = 0 if not rsMessages.EOF then rsMessages.Movefirst do until rsMessages.EOF if rsMessages("messageread") = False then newcount = newcount + 1 end if rsMessages.Movenext loop rsMessages.Movefirst end if %>