gpt4 book ai didi

php - 如何使用 php 从列中获取精确值

转载 作者:行者123 更新时间:2023-11-29 08:16:23 26 4
gpt4 key购买 nike

我想从 mysql 表中的列中获取值。 mysql 行中的值是一个简单的 2 位数字。 (40) 我尝试过:

$healthh = intval(mysql_query("SELECT health FROM users 
WHERE username = ".quote_smart($username).""));

print_r($healthh); 中,我得到 33 而不是 40。

也尝试过

$healthh = mysql_query("SELECT health FROM users 
WHERE username = ".quote_smart($username)."");

本例中的输出是资源 id #33

如果我尝试这样:

$healthh = mysql_fetch_object(mysql_query("SELECT health FROM users 
WHERE username = ".quote_smart($username).""));

我得到了正确的值,但不是整数(一个简单的 2 位数)输出:stdClass 对象 ( [health] => 40 )

有什么想法吗?

最佳答案

使用mysql_fetch_asoc()

$result = mysql_query("SELECT health FROM users 
WHERE username = ".quote_smart($username)."");

$row = mysql_fetch_assoc($result);

$healthh = $row['health'];

关于php - 如何使用 php 从列中获取精确值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20527325/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com