我查看了与我的类似问题的其他答案,但似乎无法解决这个问题。
这是代码。
$connection = mysql_connect("localhost","root","starwars");
$conn = mysql_select_db("project", $connection);
// This code assumes $itemID is set to that of
// the item that was just rated.
// Get all of the user's rating pairs
$sql = "SELECT DISTINCT r.itemID, r2.ratingValue - r.ratingValue
as rating_difference
FROM rating r, rating r2
WHERE r.userID=$userID AND
r2.itemID=$itemID AND
r2.userID=$userID;";
$db_result = mysql_query($sql, $conn);
echo "The result is {$db_result}";
$num_rows = mysql_num_rows($db_result)or die('Cannot Execute:'. mysql_error());
显示的错误是:
警告:mysql_query() 期望参数 2 是资源,布尔值在第 177 行的 C:\xampp\htdocs\recomender\ratingfiles\class.rating.php 中给出
第 177 行是
$db_result = mysql_query($sql, $conn);
如果我回$conn
显它会给出“1”的值,我认为它等于真,因此是布尔值,有什么想法吗?