在PHP中的mySQL数据库中获取最大的数目 [英] Get the Largest Number in a mySQL Database in PHP
本文介绍了在PHP中的mySQL数据库中获取最大的数目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个SQL数据库,其列如下:
I have a SQL Database that has a column like this:
ID
-----
0352
5432
4382
3520
30593
3992
295
我要做的是搜索该列,找到最大的数字(30593)并将其存储在变量中.
What I want to do is search through that column, find the largest number (30593) and store it in a variable.
此数据库还有其他列,上面的示例仅用于演示.
This database has other columns, the example above is for demonstration only.
例如
$ largestNumber =从ID中获取最大的数字
$largestNumber = GET LARGEST NUMBER FROM ID
我将如何在PHP/MySQL中做到这一点
How would I do that in PHP / MySQL
推荐答案
在PHP中,我们这样做:
In PHP, we do it like this:
$rowSQL = mysql_query( "SELECT MAX( ID ) AS max FROM `tableName`;" );
$row = mysql_fetch_array( $rowSQL );
$largestNumber = $row['max'];
这篇关于在PHP中的mySQL数据库中获取最大的数目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文