php - mysql_num_rows() 有什么问题?

标签 php mysql

我有这段代码可以获取 friend 发送给某人的用户名like user to from messagemysql_num_rows 不工作,我的用户名显示为未知。这与 mysql_num_rows() 有关系吗?

function getusername($userid) {
    $sql = "SELECT username FROM user WHERE `id` = '".$userid."' LIMIT 1";
    $result = mysql_query($sql);
    // Check if there is someone with this id
    if(mysql_num_rows($result)) {
        // if yes get his username
        $row = mysql_fetch_row($result);
        return $row[0];
    } else {
        // if not, name him Unknown
        return "Unknown";
    }
}

最佳答案

尝试回显查询并查看 ID 是否放置正确,然后确保这样的 ID 确实存在,然后在执行查询后运行 echo mysql_error() 以查看是否存在任何错误。这应该涵盖所有基础并为您提供所需的答案。

关于php - mysql_num_rows() 有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2031891/

相关文章:

php - 计算表中包含 file_name 的行数

php - 如何显示 youtube 视频缩略图

php - 向菜单栏添加向右箭头

php - Laravel/Eloquent/DB 查询 - 当为 null 且不为 null 时加入

mysql - Rails 4应用程序中多个数据库之间的切换

sql - 连接 MYSQL 表并按两个字段排序?

php - Scandir 无法打开目录

php - 交响乐 2 : dev to pro = blank page

php - 加入两个 MySQL 表并显示组合数据

mysql - 如何选择触发器(mysql)中声明的变量?