php购物车有关问题

WBOY
发布: 2016-06-13 11:20:05
原创
975 人浏览过

php购物车问题

<?php<br />  include ('book_sc_fns.php');<br />  // The shopping cart needs sessions, so start one<br />  session_start();<br /><br />  @$new = $_GET['new'];<br /><br />  if($new) {<br />    //new item selected<br />    if(!isset($_SESSION['cart'])) {<br />      $_SESSION['cart'] = array();<br />      $_SESSION['items'] = 0;<br />      $_SESSION['total_price'] ='0.00';<br />    }<br /><br />    if(isset($_SESSION['cart'][$new])) {<br />      $_SESSION['cart'][$new]++;<br />    } else {<br />      $_SESSION['cart'][$new] = 1;<br />    }<br /><br />    $_SESSION['total_price'] = calculate_price($_SESSION['cart']);<br />    $_SESSION['items'] = calculate_items($_SESSION['cart']);<br />  }<br /><br />  if(isset($_POST['save'])) {<br />    foreach ($_SESSION['cart'] as $isbn => $qty) {<br />      if($_POST[$isbn] == '0') {<br />        unset($_SESSION['cart'][$isbn]);<br />      } else {<br />        $_SESSION['cart'][$isbn] = $_POST[$isbn];<br />      }<br />    }<br /><br />    $_SESSION['total_price'] = calculate_price($_SESSION['cart']);<br />    $_SESSION['items'] = calculate_items($_SESSION['cart']);<br />  }<br /><br />  do_html_header("Your shopping cart");<br /><br />  if(($_SESSION['cart']) && (array_count_values($_SESSION['cart']))) {<br />    display_cart($_SESSION['cart']);<br />  } else {<br />    echo "<p>There are no items in your cart</p><hr/>";<br />  }<br /><br />  $target = "index.php";<br /><br />  // if we have just added an item to the cart, continue shopping in that category<br />  if($new)   {<br />    $details =  get_book_details($new);<br />    if($details['catid']) {<br />      $target = "show_cat.php?catid=".$details['catid'];<br />    }<br />  }<br />  display_button($target, "continue-shopping", "Continue Shopping");<br /><br />  // use this if SSL is set up<br />  // $path = $_SERVER['PHP_SELF'];<br />  // $server = $_SERVER['SERVER_NAME'];<br />  // $path = str_replace('show_cart.php', '', $path);<br />  // display_button("https://".$server.$path."checkout.php",<br />  //                 "go-to-checkout", "Go To Checkout");<br /><br />  // if no SSL use below code<br />  display_button("checkout.php", "go-to-checkout", "Go To Checkout");<br /><br />  do_html_footer();<br />?><br />
登录后复制


代码中的$_SESSION['cart'][$new]是什么意思,为什么要这样子做?

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!