mysql_fetch_array不在函数内部工作

时间:2014-03-09 15:44:21

标签: php mysql function

我试图加权平均值。我的5星评级脚本的价值:

function raten($setvl)
{
    global $book_id, $resulten, $dbhandle;
    $resulten =  mysql_query("SELECT SUM(rate) 
                                FROM review 
                               WHERE rate = '$setvl' AND 
                                     book_id = '$book_id",
                            $dbhandle);
    $rowen = mysql_fetch_array($resulten);
    return $rowen['SUM(rate)'];
}

有谁能解释我做错了什么?

1 个答案:

答案 0 :(得分:1)

您在查询中错过了'。变化...

"SELECT SUM(rate) FROM review WHERE rate = '$setvl' AND book_id = '$book_id"

为...

"SELECT SUM(rate) FROM review WHERE rate = '$setvl' AND book_id = '$book_id'"