There's no need to fetch all columns in the table. Should only need the username and user id. The search should also be done in the query instead of selecting all records and iterating through them in PHP to find those that match. The search code should also probably be in its own function as we probably want this elsewhere (eg the ACP, PMs, etc).