doucigua0449 2014-10-15 12:03
浏览 25
已采纳

PHP / SQL连接脚本[关闭]

someone please help me to set mysql database connection variable on below php scripts but I couldn't fixed it.

$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, $connection);
$num_rows = mysql_num_rows($db_result);
while ($row = mysql_fetch_assoc($db_result)) {
    $other_itemID = $row["itemID"];
    $rating_difference = $row["rating_difference"];
    if (mysql_num_rows(mysql_query("SELECT itemID1 
    FROM dev WHERE itemID1=$itemID AND itemID2=$other_itemID",
    $connection)) > 0)  {
        $sql = "UPDATE dev SET count=count+1, 
    sum=sum+$rating_difference WHERE itemID1=$itemID 
    AND itemID2=$other_itemID";
        mysql_query($sql, $connection);
        if ($itemID != $other_itemID) {
            $sql = "UPDATE dev SET count=count+1, 
        sum=sum-$rating_difference 
        WHERE (itemID1=$other_itemID AND itemID2=$itemID)";
            mysql_query($sql, $connection);
        }
    }
  • 写回答

1条回答 默认 最新

  • dongnianwo8289 2014-10-15 12:11
    关注

    You didn't connect to any database use some thing like this

    $link = mysql_connect('dbhost', 'dbusername', 'dbpassword');
    $connection = mysql_select_db('tablename', $link);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?