为了账号安全,请及时绑定邮箱和手机立即绑定

数据库中的值未出现在php中

数据库中的值未出现在php中

元芳怎么了 2021-05-05 14:20:02
我已经使用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因此您会有一些异常,这会在某处给您带来问题


查看完整回答
反对 回复 2021-05-20
  • 1 回答
  • 0 关注
  • 190 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号