private List <Post> getComments(int postId) { //Connect to the database and check to see if user already exists, if it does, compare the password string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString; SqlConnection conn = new SqlConnection(connectionString); string query = "select TOP(20) * from postt p left join users u on u.userid = p.puserid left join groups g on g.groupid = p.pgroupid left join member m on m.mgroupid = g.groupid where (u.userid = p.puserid or m.muserid =" + Session["UserId"] + ") and p.commentid = " + Int32.Parse(postId.ToString()) + ";"; SqlCommand cmd = new SqlCommand(query, conn); conn.Open(); //Actually execute the query and return the results SqlDataReader reader = cmd.ExecuteReader(); string[] checkarray = new string[22]; List <Post> posts = new List <Post>(); while (reader.Read()) { checkarray[0] = reader[0].ToString(); //postid checkarray[1] = reader[1].ToString(); //ptext checkarray[2] = reader[2].ToString(); //ptimestamp checkarray[3] = reader[3].ToString(); //phascom checkarray[4] = reader[4].ToString(); //commentid checkarray[5] = reader[5].ToString(); //puserid checkarray[6] = reader[6].ToString(); //pgroupid checkarray[7] = reader[7].ToString(); //pcode checkarray[8] = reader[8].ToString(); //ppicfile checkarray[9] = reader[9].ToString(); //userid checkarray[10] = reader[10].ToString(); //username checkarray[11] = reader[11].ToString(); //userrealname checkarray[12] = reader[12].ToString(); //usergitname checkarray[13] = reader[13].ToString(); //useravatar checkarray[14] = reader[14].ToString(); //useremail checkarray[15] = reader[15].ToString(); //userpassword checkarray[16] = reader[16].ToString(); //groupid checkarray[17] = reader[17].ToString(); //groupname checkarray[18] = reader[18].ToString(); //groupavatar checkarray[19] = reader[19].ToString(); //muserid checkarray[20] = reader[20].ToString(); //mgroupid checkarray[21] = reader[21].ToString(); //madmin int id = Int32.Parse(checkarray[0]); DateTime time = SqlDateHelper.parseSqlDate(checkarray[2]); bool hasComments = bool.Parse(checkarray[3]); bool isComment = checkarray[4] != null && checkarray[4] != ""; bool admin = false; if (checkarray[21] != "") { admin = bool.Parse(checkarray[21]); } int zero = 0; int one = 1; //Check to see if the user is a group admin if (checkarray[13] == "") { if (admin) { User user = new User(checkarray[17], checkarray[18], Int32.Parse(checkarray[16]), one); Control post = addFooter(UserPost.makePost(user, checkarray[1], checkarray[8], checkarray[7], time, isComment), time, id, hasComments, isComment); post.ID = "post" + id; post.ClientIDMode = System.Web.UI.ClientIDMode.Static; // this supposedly makes client ID's the same as ASP ID's posts.Add(new Post(post, time)); } else { User user = new User(checkarray[17], checkarray[18], Int32.Parse(checkarray[16]), zero); Control post = addFooter(UserPost.makePost(user, checkarray[1], checkarray[8], checkarray[7], time, isComment), time, id, hasComments, isComment); post.ID = "post" + id; post.ClientIDMode = System.Web.UI.ClientIDMode.Static; // this supposedly makes client ID's the same as ASP ID's posts.Add(new Post(post, time)); } } else { if (Int32.Parse(checkarray[9]) == Int32.Parse(Session["UserId"].ToString())) { User user = new User(checkarray[10], checkarray[13], Int32.Parse(checkarray[9]), one); Control post = addFooter(UserPost.makePost(user, checkarray[1], checkarray[8], checkarray[7], time, isComment), time, id, hasComments, isComment); post.ID = "post" + id; post.ClientIDMode = System.Web.UI.ClientIDMode.Static; // this supposedly makes client ID's the same as ASP ID's posts.Add(new Post(post, time)); } else { User user = new User(checkarray[10], checkarray[13], Int32.Parse(checkarray[9]), zero); Control post = addFooter(UserPost.makePost(user, checkarray[1], checkarray[8], checkarray[7], time, isComment), time, id, hasComments, isComment); post.ID = "post" + id; post.ClientIDMode = System.Web.UI.ClientIDMode.Static; // this supposedly makes client ID's the same as ASP ID's posts.Add(new Post(post, time)); } } } reader.Close(); conn.Close(); return(posts); }