打印资源id #5.不知道怎么解决


getting resource id #5 printed.dont know what is the solution

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

正在打印资源id #5。不知道有什么问题吗?

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

摘自PHP文档:

$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_*函数将在PHP 5.5中弃用。不建议编写新代码,因为它将在将来被删除。相反,无论是MySQLi还是PDO,都可以成为更好的PHP开发人员。