I have 4 tables:
- Users
- Forums
- Discussies (discussions)
- Forumberichten (messages)
The table Forumberichten (messages) contains the id's of the Discussion (discussions) table as a reference to reactions on a discussion. If there are 5 reactions to a discussion, there are 5 id's in the table with the same value.
How do I display an echo of one discussion of every different discussion with the latest reaction on it?
I've tried ORDER BY, DISTICT, GROUP BY and other things but I can't get it to work. I keep getting more outputs of the same discussion or one discussion with the original input and not the latest reaction to it.
<?php
// DISCUSSIES FORUM SCHRIJVEN
$sql="SELECT forumberichten.discussieid,forumberichten.datum,discussies.discussieid,discussies.titel,discussies.forumid,discussies.highlight,forums.forumid,forums.forumnaam,users.userid,users.userimage,users.username FROM forumberichten,discussies,forums,uers WHERE forumberichten.discussieid=discussies.discussieid AND discussies.forumid=forums.forumid AND forumberichten.userid=users.userid AND forums.forumid=1 ORDER BY forumberichten.bericht_id DESC LIMIT 3";
$result = $conn->query($sql) or die ("The query could not be completed. try again");
if ($result->num_rows > 0) {
echo "
<br>
<table id='forumschrijvenklein'>
<tbody>
<tr>
<td bgcolor='#1E1E1E'></td>
<td nowrap bgcolor='#1E1E1E'> </td>
<td nowrap bgcolor='#1E1E1E' class='sterrenkleur'>Discussie</td>
<td nowrap bgcolor='#1E1E1E' class='sterrenkleur'>Laatste reactie</td>
<td nowrap bgcolor='#1E1E1E' class='sterrenkleur'>Datum</td>
<td nowrap bgcolor='#1E1E1E' class='sterrenkleur'></td>
</tr>
";
// output data of each row
while ($row = $result->fetch_assoc()) {
echo"
<tr>";if ($row["highlight"] == '1') {
echo " <td bgcolor='#FC6'></td>";
} else {
echo "<td bgcolor='#1E1E1E'></td>";
}
echo"
<td nowrap bgcolor='#1E1E1E'>";if ($row["userimage"] == '') {
echo "
<a href='user.php? id=" . $row['userid'] . "'</a><img src='Images/users/nopicture.png' alt='nopicture' class='userimage-tooltip-small' title='".$row['username']."''></a>";
} else {
echo "<a href='user.php? id=" . $row['userid'] . "'</a><img src='Images/users/".$row['userimage']."' class='userimage-tooltip-small' title='".$row['username']."''></a>";
}
echo"</td>
<td bgcolor='#1E1E1E'><a href='discussie.php? id=" . $row['discussieid'] . "'>".$row["titel"]."</a></td>
<td bgcolor='#1E1E1E'><a href='user.php? id=" . $row['userid'] . "'</a>".$row["username"]."</a></td>
<td nowrap bgcolor='#1E1E1E'>"; echo date("d-m-y H:i",strtotime($row["datum"]));"
";
echo"
</td>
<td nowrap bgcolor='#1E1E1E'></td>
</tr>
";
}
}
echo "
<tr>
<td bgcolor='#1E1E1E'> </td>
<td bgcolor='#1E1E1E'> </td>
<td bgcolor='#1E1E1E'><img src='Images/lijntransparant.png' width='315' height='2'></td>
<td bgcolor='#1E1E1E'><img src='Images/lijntransparant.png' width='140' height='2'></td>
<td bgcolor='#1E1E1E'> </td>
<td bgcolor='#1E1E1E'> </td>
</tr>
</tbody>
</table>
";
}
?>
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire