[英]How to get the exact value from a column with php
I want to get the value from a column in a mysql table. 我想从mysql表中的列中获取值。 The value from the mysql row is a simple number of 2 figures. mysql行的值是2个数字的简单数字。 (40) I tried: (40)我试过:
$healthh = intval(mysql_query("SELECT health FROM users
WHERE username = ".quote_smart($username).""));
and in print_r($healthh);
并在print_r($healthh);
I get 33 instead of 40. 我得到33而不是40。
tried also 也尝试过
$healthh = mysql_query("SELECT health FROM users
WHERE username = ".quote_smart($username)."");
OUTPUT IS in this case Resource id #33 在这种情况下,输出是资源ID#33
if i try like this: 如果我这样做:
$healthh = mysql_fetch_object(mysql_query("SELECT health FROM users
WHERE username = ".quote_smart($username).""));
I get the right value but not as an integer (a simple 2 figure number) OUTPUT: stdClass Object ( [health] => 40 )
我得到正确的值但不是整数(简单的2位数字)OUTPUT: stdClass Object ( [health] => 40 )
Any ideas? 有任何想法吗?
Use mysql_fetch_asoc() 使用mysql_fetch_asoc()
$result = mysql_query("SELECT health FROM users
WHERE username = ".quote_smart($username)."");
$row = mysql_fetch_assoc($result);
$healthh = $row['health'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.