Reputation: 263
I would like to fetch the time at which the latest record was made by a particular user.
Say there are 4 rows made by a user containing their distinct ID, called steamid
. They were all made at different times. I would like to get the time at which the latest one was made.
So to select the bottom record I tried.
$time = "SELECT max(time) FROM bets WHERE steamid='$number'";
$result = mysqli_query($conn,$time);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
$previous = $row["time"];
}
} else {
$previous = '0';
}
However a dump of $previous
returns null.
Upvotes: 0
Views: 23
Reputation: 44911
In the result there will be no column named time
as you haven't given any alias to the result of max(time)
Change the query to this: SELECT max(time) as time ...
Upvotes: 1