Check information from another array
I have 2 tables in the database, the table circle and the table gossips.
The table circle has 3 columns: id, idfrom, idto.
The table gossips has id, userid, gossip.
My objectif is to echo all the gossips only if the userid of this gossip
(idto) and the id of the pageuser(idfrom) are on the same row in the table
circle. I wrote this code,
$query = 'SELECT * FROM gossips ORDER BY id DESC';
$result = mysqli_query($cxn, $query)
or die("Couldn't execute query");
$querycircle = 'SELECT idfrom,idto FROM circle WHERE
idfrom="{$pageuserid}" ';
$resultcircle = mysqli_query($cxn, $querycircle)
or die("Couldn't check if user in circle.");
while($row = mysqli_fetch_assoc($result))
{
while($rowcheck = mysqli_fetch_assoc($resultcircle))
{
if($row['userid'] == $rowcheck['idto'] || $row['userid'] ==
$_COOKIE['id']){
echo '<div class="gossip">'.$row['gossip'].'</div>';
}
}
}
But it doesn't seem to work properly.
No comments:
Post a Comment