Php添加到购物车项目冗余

时间:2016-09-27 14:18:52

标签: php

我有一个购物车,可以将商品添加到购物车会话中。如果另一个相同的项目添加到购物车,则会显示重复的项目,每个项目的数量为1。

我需要添加/更改代码以更新现有项目的数量?而不是添加重复的项目。

 </head>
  <body>    
   <!-- Pre Loader -->
  <a id="aa-preloader-area">
  <div class="pulse"></div>
  </a>
 <!-- SCROLL TOP BUTTON -->
    <a class="scrollToTop" href="#"><i class="fa fa-angle-double-up"></i></a>
  <!-- END SCROLL TOP BUTTON -->

  <!-- Start header section -->
        <div class="header_top">
      <div class="container">
        <div class="row">
          <div class="col-sm-6">
            <div class="contactinfo">
              <ul class="nav nav-pills">
              </ul>
            </div>
          </div>
          <div class="col-sm-6">
            <div class="social-icons pull-right">
              <ul class="nav navbar-nav">
                <li><a href="#"><i class="fa fa-facebook"></i></a></li>
                <li><a href="#"><i class="fa fa-twitter"></i></a></li>
                <li><a>
                    Welcome:
                    <?php
                    $user_query = mysql_query("select * from tb_member where memberID='$ses_id'") or die(mysql_error());
                    $row = mysql_fetch_array($user_query);
                    echo $row['Firstname'] . " " . $row['Lastname'];
                    ?>
                </li></a>
                <li><a href="logout.php">&nbsp;Log out</li></a>
              </ul>
            </div>
          </div>
        </div>
      </div>
    </div>







 <header>
    <nav>
      <ul>
        <ul><li style ="margin-left:100px;"><a href="index.php"><img src="logo/3.jpg" width="185" height="65" sizes="210px"/></a></li>
  <li style ="margin-left:380px;"><a href="user_home.php">HOME</a></li>
  <li><a href="user_category.php">HEALTH</a></li> 
        <li><a href="user_category.php">SHOP</a></li> 
        <li><a href="user_about_us.php">ABOUT US</a></li>
        <li><a href="user_contact_us.php">CONTACT US</a></li>
        <li><a href="user_faqs.php">FAQs</a></li>
  <li><a href="user_cart.php">My Cart <span class="badge"><?php
                    $count_query = mysql_query("select * from order_details where memberID='$ses_id' and status='Pending'") or die(mysql_error());
                    $count = mysql_num_rows($count_query);
                    ?>
                    <?php echo $count; ?>  </span></a></li>
  </ul>
    </nav>
  </header>
<br>
<br>
  <!-- End menu section -->




    <div id="background">


        <div id="page">

            <div id="content">
                <div class="hero-unit-table">
                    <div id="header">


                    </div>
                    <div id="body">
                        <h3>Cart</h3>
                        <div class="hero-unit-table">

                            <table class="table table-bordered">

                                <thead>
                                    <tr>
                                        <th>Product Name</th>
                                        <th>Price</th>
                                        <th>Quantity</th>
                                        <th>Amount</th>
                                        <th>Action</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                    $cart_table = mysql_query("select  * from order_details where memberID='$ses_id' and status='Pending'") or die(mysql_error());
                                    $cart_count = mysql_num_rows($cart_table);
                                    while ($cart_row = mysql_fetch_array($cart_table)) {
                                        $order_id = $cart_row['orderid'];
                                        $product_id = $cart_row['productID'];
                                        $product_query = mysql_query("select * from tb_products where productID='$product_id'") or die(mysql_error());
                                        $product_row = mysql_fetch_array($product_query);
                                        ?>

                                        <tr>
                                            <td><?php echo $product_row['name']; ?></td>
                                            <td><?php echo $cart_row['price']; ?></td>
                                            <td><?php echo $cart_row['qty']; ?></td>
                                            <td><?php echo $cart_row['total']; ?></td>
                                            <td width="100"><a href="#orderdel<?php echo $order_id; ?>" role="button"  data-toggle="modal" class="btn btn-danger"><i class="icon-remove icon-large"></i>&nbsp;Remove</a></td>
                                        </tr>
                                        <!-- product delete modal -->
                                    <div id="orderdel<?php echo $order_id; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                        <div class="modal-header">
                                        </div>
                                        <div class="modal-body">
                                            <div class="alert alert-danger">Are you Sure you want to <strong>Remove &nbsp;</strong>this item?</div>
                                        </div>
                                        <div class="modal-footer">
                                            <a class="btn btn-danger" href="romove_item.php<?php echo '?id=' . $order_id; ?>" ><i class="icon-check icon-large"></i>&nbsp;Yes</a>
                                            <button class="btn" data-dismiss="modal" aria-hidden="true"><i class="icon-remove icon-large"></i>&nbsp;No</button>

                                        </div>
                                    </div>
                                    <!-- end delete modal -->

                                <?php } ?>

                                </tbody>
                            </table>




                        </div>

                        <?php
                        if ($cart_count != 0) {
                            $result = mysql_query("SELECT sum(total) FROM order_details WHERE memberID='$ses_id' and status = 'Pending'") or die(mysql_error());
                            while ($rows = mysql_fetch_array($result)) {
                                ?>
                                <center> <a href="#order" role="button"  data-toggle="modal"class="btn btn-success"><i class="icon-truck icon-large"></i>&nbsp;Order Payments?</a></center>
                                <div class="pull-right">
                                    <div class="span"><div class="alert alert-success"><i class="icon-credit-card icon-large"></i>&nbsp;Total:&nbsp;<?php echo $rows['sum(total)']; ?></div></div>
                                </div>
                            <?php }
                            ?>
                            <?php
                        }
                        ?>


                        <!-- product order modal -->
                        <div id="order" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                            <div class="modal-header">
                            </div>
                            <div class="modal-body">
                            <div class="alert alert-info" style ="font-size:14pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Payment: Cash on Delivery, Pick-up or Online Bank</div>
                             <div class="alert alert-danger"><ol><li type ="square" style ="font-size:13.5px;text-align:justify;">By reading this you Agree to the&nbsp;<strong>Terms and Condition &nbsp;</strong>of this Company
                                                            <ol>
                             <br> 
                             <ol>
                            <li type ="circle">All copyright, trade marks, design rights, patents and other intellectual property rights (registered and unregistered).<br>
                             <li type ="circle">Business Success Today Content belong to the BST and/or third parties (which may include you or other users.)
                             <li type ="circle">Nothing in the Terms grants you a right or licence to use any trade mark, design right or copyright owned or controlled by the Business Success Today
                             or any other third party except as expressly provided in the Terms.</div>
                        </ol> 







                            </div>
                            <div class="modal-footer">
                                <a class="btn" href="pay.php<?php echo '?id='.$ses_id; ?>"><i class="icon-check"></i>&nbsp;Yes</a>
                                <button class="btn" data-dismiss="modal" aria-hidden="true"><i class="icon-remove"></i>&nbsp;No</button>

                            </div>
                        </div>
                        <!-- end delete modal -->

                    </div>

                </div>
            </div>
        </div>
    </div>




  <br><br><br><br>
<!-- Footer -->
 <nav id="aa-footer">
    <div class="container">
      <div class="row">
        <div class="col-md-12">
        <div class="aa-footer-area">
          <div class="row">
            <div class="col-md-3 col-sm-6 col-xs-12">
              <div class="aa-footer-left">
               <p>Designed by <a rel="nofollow" href="#">Business.com</a></p>
              </div>
            </div>
            <div class="col-md-3 col-sm-6 col-xs-12">
              <div class="aa-footer-middle">
                <a href="#"><i class="fa fa-facebook"></i></a>
                <a href="#"><i class="fa fa-twitter"></i></a>
                <a href="#"><i class="fa fa-google-plus"></i></a>
                <a href="#"><i class="fa fa-youtube"></i></a>
              </div>
            </div>
            <div class="col-md-6 col-sm-12 col-xs-12">
              <div class="aa-footer-right">
                <a href="user_home.php">Home</a>
                <a href="user_about_us.php">About Us</a>
              </div>
            </div>            
          </div>
        </div>
      </div>
      </div>
    </div>
  </nav>

0 个答案:

没有答案