简体   繁体   English

如何从MySQL查询中将MAX值赋给PHP变量?

[英]How to assign MAX value from mySQL query into PHP variable?

I want to store the MAX value of the following mySQL query : 我想存储以下mySQL查询的MAX值:

$maxTF = mysql_query("SELECT MAX(tf) AS maxTF FROM my_database")or die(mysql_error());

echo $maxTF;

But i didn't get the value. 但是我没有得到价值。 Could someone tell how to make it works ? 有人可以告诉我如何使它起作用吗? thanks in advance. 提前致谢。

$maxTF isn't the value being selected, it's the result of the query . $maxTF不是选择的值,而是查询结果 Which is an object itself from which you can fetch records and values. 这是一个对象本身,您可以从中获取记录和值。 In this case exactly one record will be returned by this query, and that record will contain exactly one value. 在这种情况下,此查询将仅返回一条记录,并且该记录将仅包含一个值。

Looking at the documentation shows some examples you can use. 查看文档显示了一些可以使用的示例。 (When doing so, do also pay attention to that red box at the top of the page. You're using a data connection library that's no longer supported.) Something like this: (这样做时,还请注意页面顶部的红色框。您正在使用不再受支持的数据连接库。)

$row = mysql_fetch_assoc($maxTF);
echo $row['maxTF'];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM