I'm trying to get the row with the highest ID from a group, rather than the lowest. I heard you have to do that JOIN
trick, but it's confusing and I can't get my head around it.
My code so far is this:
$userp0l=//userID
$where=//forumID
SELECT *
FROM `noti`
WHERE forum='$where'
AND user <> '$userp0l'
GROUP BY user
ORDER BY `id`
DESC
It works, however it is showing the first entry in the group, rather than the latest. Anyone know how I can rewrite this?
I just said I'd post all of my code, but looking at it, there's not really much else. I run this statement:
$elist = mysql_query("SELECT * FROM `noti` WHERE forum='$where' AND user <> '$userp0l' GROUP BY user ORDER BY `id` DESC") or die(mysql_error());
It gets the information from the database. The information is grouped so I do not capture a user twice when I go to renter data into the table:
if(mysql_num_rows($elist) > 0){
while($elist_result = mysql_fetch_array($elist)){
$shownotir=$elist_result['shownoti'];
$userr=$elist_result['user'];
$forumr=$elist_result['forum'];
if($shownotir=="n"){
$pps="INSERT INTO `noti`(`user`, `forum`, `shownoti`, `forumn`, `madeby`) VALUES ('$userr', '$where', '0', '$forumn', '$uu')";
mysql_query($pps) or die(mysql_error());
}
else {
$pps="INSERT INTO `noti`(`user`, `forum`, `shownoti`, `forumn`, `madeby`) VALUES ('$userr', '$where', '1', '$forumn', '$uu')";
mysql_query($pps) or die(mysql_error());
}
}
}
I need to find if the most recent entry of shownoti
is a 1
or a 0
. The trouble is, when grouping, it takes the first entry rather than the latest. So if the most recent entry has a shownoti
value of 0
, but the first entry value has a 1
, it will always show 1
as it is seeing the first entry. I want to order the groups backwards, basically.