获取资源ID#5 printed.dont知道解决方案是什么

时间:2013-03-19 14:37:07

标签: php mysql

$u=$_SESSION['username'];
$p=$_SESSION['password'];
$a = mysql_query("SELECT section FROM users WHERE username ='$u' AND password ='$p'");
echo "$a";

获取资源ID#5 printed.dont知道问题是什么?

1 个答案:

答案 0 :(得分:2)

查询返回资源对象。您需要遍历资源以获取每条记录。

取自PHP Docs

$result = mysql_query($sql);

if (!$result) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
}

if (mysql_num_rows($result) == 0) {
    echo "No rows found, nothing to print so am exiting";
    exit;
}

while ($row = mysql_fetch_assoc($result)) {
    echo $row["userid"];
    echo $row["fullname"];
    echo $row["userstatus"];
}

注意: mysql_*函数将为deprecated in PHP 5.5。建议不要编写新代码,因为将来会将其删除。相反,可以是MySQLiPDObe a better PHP Developer