我正在编写购物车代码,但总价有问题。
这是我尝试编写的函数:
function get_total_price(){
$result=mysql_query("SELECT SUM(price) FROM db.cart WHERE user_id='".mysql_real_escape_string($_SESSION['user_id'])."'") or die();
return $result;
}
但结果我得到了
Resource id #10
希望有人能帮忙。首先我开始没有函数的编码,但现在我想学习如何创建 php 函数等。
最佳答案
您正在使用 mysql_*
函数的已弃用版本。请参阅http://php.net/manual/en/book.mysqli.php或 PDO:http://php.net/manual/en/ref.pdo-mysql.php .
顺便说一句,现在您必须使用:mysql_fetch_array()
函数来获取数组。
示例:
while ( $row = mysql_fetch_array($result) )
{
print_r($row);
}
关于php mysql 获取总价,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19455003/