So, I'm trying to create an area called "shoutout" where the current user may view "shoutout", basically messages from the shoutout table from people that are friends with him/her.
So, what I did was first put all the current user's friends into an array called "currentuserfriends", then I wish to select message from the shoutout table where username = all the users in "currentuserfriends".
However I have no idea how to loop in a select statement,
I don't want to have to do something like,
string getuserfriendlist = "SELECT friend FROM friend WHERE username = '" + currentuserfriends[0] + "'";
and increase currentuserfriends[0] manually. Is there a way to loop currentuserfriends until the end in a single select statement? Thanks.
Friend table
username | friend
shoutout table
username | message | datetime
Code:
        string[] currentuserfriends = new string[9999];
string[] posternames = new string[9999];
    string getuserfriendlist = "SELECT friend FROM friend WHERE username = '" + currentuser + "'";
    SqlCommand cmdb = new SqlCommand(getuserfriendlist, con);
    SqlDataReader drb;
    drb = cmdb.ExecuteReader();
    while (drb.Read())
    {
        string currentuserfriend = drb["friend"].ToString();
        currentuserfriends[l++] = currentuserfriend;
    }
    drb.Close();
    string getshoutout = "SELECT * FROM shoutout WHERE username = '" + currentuserfriends + "' AND username ='" + currentuser + "' order by datetime DESC";
    SqlCommand cmdc = new SqlCommand(getshoutout, con);
    SqlDataReader drc;
    drc = cmdc.ExecuteReader();
    while (drc.Read())
    {
        string postername = drb["username"].ToString();
        posternames[m++] = postername;
    }
    drc.Close();
    Label2.Text = posternames[0];
    Label3.Text = posternames[1];
    Label4.Text = posternames[2];
    Label5.Text = posternames[3];
    Label6.Text = posternames[4];
 
     
     
     
     
    