can`t MAX() function be used with mysqli?
I can not find a proper answer to this question. I have a very simple code
for making a query in mysql to select the row with the maximum value in a
determined column (called popularity) from a table (called comments).
Every row has a column named comment_id
here is the code:
$connect_error = 'Sorry, try again, there was a connection error';
$con = mysqli_connect('localhost','user_name','password') or
die($connect_error);
mysqli_select_db($con, 'database') or die($connect_error);
$result = mysqli_query($con, "SELECT MAX(`popularity`) FROM `comments`");
while ($row = mysqli_fetch_assoc($result)) {
$most_popular = $row['comment_id'];
}
echo "most popular is: $most_popular";
mysqli_free_result($result);
mysqli_close($con);
the screen does not show a proper result. Can someone give me an advice in
this regard?
Thank you
No comments:
Post a Comment