gpt4 book ai didi

php - MYSQL 查询返回“资源 id#12”而不是它应返回的数值

转载 作者:行者123 更新时间:2023-11-29 13:19:00 25 4
gpt4 key购买 nike

不知道为什么,但这返回了错误的值。我正在取回此资源 ID #12,而不是我正在寻找的数值“1”..

执行此操作的代码是:

$type = "SELECT account_type from user_attribs WHERE username = '$username'";
$usertype= mysql_query($type);

所以我将其更改为:

$type = "SELECT account_type from user_attribs WHERE username = '$username'";
$type_again = mysql_query($type);
$usertype = mysql_fetch_row($type_again);

现在它只给我单词数组。我对此完全迷失了。帮忙?!

编辑::

当前使用的代码是:

  $username= 'lmfsthefounder';
$type = "SELECT account_type from user_attribs WHERE username='lmfsthefounder';";
$type_again = mysql_query($type);
$row = mysql_fetch_row($type_again);
$usertype = $row['account_type'];
echo $usertype;

返回如下:主页登录注册用户类型是

(这应该在我的导航栏中显示“Usertype is 1”)

最佳答案

你就快到了。您有包含 MySQL 结果的行,这就是 mysql_fetch_row() 返回的内容。将其更改为 mysql_fetch_assoc()这使您的代码更具可读性。然后,您只需要您要查找的特定列值,您可以通过使用其名称作为数组键来访问该列值:

$type = "SELECT account_type from user_attribs WHERE username = '$username'";
$type_again = mysql_query($type);
$row = mysql_fetch_assoc($type_again);
echo $row['account_type'];

Please, don't use mysql_* functions in new code 。它们不再维护and are officially deprecated 。请参阅red box ?了解 prepared statements相反,并使用 PDOMySQLi -this article将帮助您决定哪个。如果您选择 PDO,here is a good tutorial .

关于php - MYSQL 查询返回“资源 id#12”而不是它应返回的数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21105034/

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