drrqwokuz71031449 2015-09-25 09:25
浏览 345

如何从PHP中获取数据库的最大值?

$link=mysqli_connect("localhost","root","","tbl_app");
$sql="SELECT MAX(tokenno) AS max FROM tbl_order";
$result=mysqli_query($link,$sql);    

while($row=mysqli_fetch_assoc($result))
$tokenaabselect=$row['max'];
echo $tokenaabselect;

Database Design:

id   name  tokenno      
------------------
1     ram     1
2     harry   2
3     sam     6
4     ham     7
5     san     8
6     nan     9
7     hell    10

I am trying to get the maximum value from the database and i am running above code.

Now the problem, I am getting from this code is it select maximum value from tokenno as 9 where as it have to select maximum value as 10.

I don't know if the maximum value from database is 8 than it works but when maximum value on database is 10 than it select 9 or 8 the single digit highest value. I don't know what is the problem.

Please help me to select maximum value 10 from the database. Looking for positive response.

  • 写回答

3条回答 默认 最新

  • dox19458 2015-09-25 09:28
    关注

    Please change you data type to int i think you datatype is string type

    评论

报告相同问题?