最近我从 php 开始,而不是因为它给了我这个错误。此代码仅用于显示文章和重新加载页面时购物车的总价格,使用 PHPSESSID,如果他们对该功能有更好的想法或替代方案,他们将不胜感激!
索引.PHP
<?php require("php/DB_Functionss.php"); ?>
<!doctype html>
<html lang="es">
<head>
........
</head>
<body>
<div id="infoShopCart">
<a href="contShopping"><img src="img/shopping_cart.png" width="30px"/>
Artículos: <b id="cantArticles">0</b>
Total: $ <b id="totalPriceArticles">0.00</b></a>
<?php getCart(); ?>
</div>
.....
....
</body>
</html>
和DB_Functions.php
session_start();
$sessionID = $_COOKIE['PHPSESSID'];
class DB_Functions {
private $db;
//put your code here
//constructor
function __construct() {
require_once 'DB_Connect.php';
//connecting to database
$this->db = new DB_Connect();
$this->db->connect();
}
//destructor
function __destruct() {
}
public function getCart(){
$query ="SELECT * FROM carrito ORDER BY id_pelicula";
$result = mysql_query($query) or die(mysql_error());
$no_of_rows = mysql_num_rows($result);
if($no_of_rows > 0) {
while ($row = mysql_fetch_assoc($result)) {
$totalItems = $totalItems + 1;
$movieTotalPrice = $movieTotalPrice + $row['precio_pelicula'];
}
echo ("Artículos: <b id='cantArticles'>"+$totalItems+"</b><otal: $ <b id='totalPriceArticles'>"+$totalPrice+"</b></a>");
} else {
return false;
}
}