Lets say I have the database table setup in this fashion,
ID | Name | Area | Timestamp
---+-------+------+------------
1 | Hill | 1 | 1293243080
2 | Sam | 1 | 1293243084
3 | Joe | 2 | 1293243087
4 | Bob | 2 | 1293243089
5 | Matt | 3 | 1293243091
6 | Billy | 3 | 1293243095
Then I wish to return the Name of the person with the largest Timestamp and with a certain Area number.
However, when I try to return for example the Name Bob I only get Billy because he has the largest Timestamp of everyone.
How can I get the php to select not only the person with the max Timestamp, but the person with a certain Area number also?
This is my code so far –
(I am looping it because I am displaying the name of the person with the largest Timestamp in each Area)
for ($t = 1; $t <= 3; $t++){
$result = mysql_query("SELECT * FROM forum_posts WHERE Area='$t' AND Timestamp=(select max(Timestamp) from forum_posts)");
while($row = mysql_fetch_array($result))
{
$post_name[$t]=$row['Name'];
}
}
print_r ($post_name);
What do you guys suggest I do?
a better option would be.