我已经使用sql,html和php创建了一个购物车网站。购物车按钮如下:<form method="post" action="cart.php" class="form-inline"><input type="hidden" value="' . $product['id'] . '" name="product_id"><input type="hidden" value="add_to_cart" name="add_to_cart"><button type="submit" name="id" value="12" class="btn btn-primary">Add to Cart</button></form>这是我的购物车外观:<div class="card"> <h5 class="card-header">My Cart</h5> <div class="card-body"> <?php if(isset($_SESSION['shopping_cart']) && count($_SESSION['shopping_cart']) > 0) { $entertainment = $_SESSION['shopping_cart']; echo ' <table class="table table-hover table-bordered"> <thead> <tr> <th scope="col">#</th> <th scope="col">Title</th> <th scope="col">Quantity</th> <th scope="col">Price</th> <th scope="col" width="100">Action</th> </tr> </thead>'; $item_number = 1; $total = 0; foreach ($entertainment as $product) { echo ' <tbody> <tr> <th scope="row">'. $item_number .'</th> <td>' . $product['title'] . '</td> <td>'.$product['quantity'].'</td> <td>$ '. $product['offer_price_corporate_artist']. '</td> <td>问题是,当我向购物车中添加商品时,我可以显示标题和购物车。但是我无法显示价格,该价格的字段名称在我的数据库中为offer_price_corporate_artist。谁能告诉我我所缺少的。
1 回答
开满天机
TA贡献1786条经验 获得超13个赞
您的购物车模型将offer_price_corporate_artist列放入返回的数组中,称为重命名事件price
$data['price'] = $row['offer_price_corporate_artist'];
因此,在其他脚本中替换
<td>$ '. $product['offer_price_corporate_artist']. '</td>
和
<td>$ '. $product['price']. '</td>
小警告
不幸的是,该
getProducts()方法未将列重命名为,price因此您会有一些异常,这会在某处给您带来问题
添加回答
举报
0/150
提交
取消
