So I have a while loop which generates all the inbox messages for a user, then inside that while loop, I have a query and another while loop which generate all the recipients of that message. I am trying to build up an array from that inside while loop which will echo all the recipients/participants of each individual message thread. As is, when I var_dump my usernamesarray, It gets built up to contain all the recipients of all the messages (by the final time it is echoed). SO, how would I go about making this array unique to each row? I am sure this is a common issue, but I cannot seem to find the search terms to learn much about it.
if (count($numbermessages)) {
while ($stmt->fetch()) {
$getrecipusernames= $mysqli->prepare("SELECT distinct(message_recips.userid), users.username, users.id FROM message_recips INNER JOIN users ON users.id=message_recips.userid WHERE messageid=?");
$getrecipusernames->bind_param('i', $messageid);
$getrecipusernames->execute();
$getrecipusernames->store_result();
$getrecipusernames->bind_result($recipuserid, $recipusername, $recipuserid1);
$getrecipusernames->fetch();
while ($getrecipusernames->fetch()) {
$usernamesarray[] = $recipusername;
}
$date_time=$created_on;
$dte_new=date("l H:i A", strtotime($date_time));
if ($status=="A"){
$message_read_status="read";
}
else {
$message_read_status="unread";
}
Sincere thanks for any help!