$resourcesbuilt = mysql_query("SELECT resourcesbuilt FROM user WHERE username = '$username' LIMIT 1");

if ($resourcesbuilt<=0 )
{
    mysql_query("INSERT INTO resources (username, dollars) VALUES ( '$username', '1000')") or die (mysql_error());
    mysql_query("UPDATE user SET resourcesbuilt = '1' WHERE username = '$username'");
}

Basically I have a column in a user table that acts as a flag that tells me whether a different table has been made for that particular user. Its 0 if it hasn't, and 1 if it has. However it seems I can't just store the query into a variable and check if its 0 or not, because the actual value from the query isn't stored in the var. When I echo the var it just says Resource id #3. My research into php and SQL has failed me. Does anyone know of a way to store the result form a sql query into a variable in php? Or can at least point me in the right direction? Thanks in advance.

基本上我在用户表中有一个列作为一个标志,告诉我是否为该特定用户创建了一个不同的表。如果没有则为0,如果有则为0。但是,似乎我不能将查询存储到变量中并检查它是否为0,因为查询中的实际值不存储在var中。当我回应var时,它只是说资源ID#3。我对php和SQL的研究让我失望了。有谁知道一种方法将结果从sql查询存储到php中的变量?或者至少可以指出我正确的方向?提前致谢。

2 个解决方案

#1


The problem is that the result returned by mysql_query is not usable in this way. Instead, you have to call

问题是mysql_query返回的结果不能以这种方式使用。相反,你必须打电话

$value = mysql_fetch_array($resourcesbuilt, MYSQL_ASSOC)
$value ["resourcesbuilt"]

This will give you the value of that field in the table. Look here for an example.

这将为您提供表中该字段的值。在这里看一个例子。

更多相关文章

  1. MySql查询脚本,每月统计活动用户。
  2. MySQL用户管理(5.7.20-winx64)
  3. Laravel - 如何为用户赋予多重角色?
  4. Linux下修改MySQL用户(root)密码
  5. MySQL:ERROR 1227(42000):访问被拒绝 - 无法创建用户
  6. 在数据库设计中使用用户名作为主键是不是很糟糕?
  7. 为mysql数据备份建立最小权限的用户
  8. MySQL查询返回用户的收件人列表
  9. c语言把mysql数据库语句和变量封装为一个语句

随机推荐

  1. 在android中运行java main方法
  2. 使用线程设置后台进程以处理Android中的
  3. [Android Pro] Android 打包流程
  4. Android 两种制作圆形/圆角图片的方法
  5. Android - 在一个应用程序中启动另外一个
  6. Kotlin控制流、返回与跳转
  7. Android添加USB连接提示音(SettingsProvid
  8. 如何在Android设备中创建Web服务器(用于远
  9. android应用私有存储文件的写入与读取-op
  10. 如何从Android中的人脸检测部分找出脸部