PHP MySQL 查询

标签 php mysql

我试图从我的表中回显一些数据,只是我的查询有问题,

$userid = (int) $explode[0];

$userrr = mysql_query("SELECT credits FROM produgg_users WHERE id = $userid");
echo $userid; // For debugging purposes
echo $userrrr;

我的 $userid 变量返回一个值很好,只是我的查询似乎没有工作,因为没有返回任何东西。

最佳答案

您需要从查询中获取结果。

    $query = "SELECT credits FROM produgg_users WHERE id = $userid";
    $result = $db->query($query);

    $hits = $result->num_rows;


    for ($i = 0; $i < $hits; $i++) {
            $row = $result->fetch_assoc();
            array_push($results, $row['name']);
    }

    return $results;

关于PHP MySQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6348668/

相关文章:

mysql - SQLSTATE[23000] : Integrity constraint violation: 1452 Cannot add or update a child row on CONSTRAINT `fk_users_has_ratings_businesses1

php - 使用php脚本在csv文件中插入图像

php - MySQL 选择时间戳列作为秒

PHP SQL 仅每隔两个条目

mysql - 数据库模式,默认值为 NOW()

php - 变量转储不显示

PHP/MYSQL 将当前时间插入日期时间

php - 如何使用 Mysql 和 PHP 插入具有相同名称的多行

c++ - 拒绝从 C++ 驱动程序连接到 mysql 数据库

mysql - MariaDB 10.0.20 服务器上的 Ruby on Rails 外键迁移不适用