需要从数据库表中获取最大值

时间:2015-12-29 09:09:47

标签: mysql max

我试图从数据库中获取最大值,但它对我不起作用。那我做错了吗?

  $con = mysqli_connect($servername, $username, $password, $dbname);
 $query_for_com = "SELECT MAX(id) FROM Comments";
    $mysql_query5= mysqli_query($con,$query_for_com);
    while ($query_row_com = mysqli_fetch_assoc($mysql_query5)) {
    echo $id_for = $query_row_com['Id'];
}

1 个答案:

答案 0 :(得分:1)

尝试这种方法:

$query_for_com = "SELECT id FROM Comments ORDER BY id DESC LIMIT 1";