欢迎光临
我们一直在努力

使用方法-PHP教程,PHP应用

建站超值云服务器,限时71元/月

这是我当时写的一个列出所有购物车中的清单的程序,各位可自己根据需要改写一下
<?php
    ob_start();
    session_start()                 ;
/*
    $s=array("id" => 6, "name" => "测试a", "price" => "6", "count" =>3);
    $t=array("id" => 7, "name" => "测试b", "price" => "7", "count" =>15);
    $u=array("id" => 8, "name" => "测试c", "price" => "8", "count" =>21);
    $rst=array($s, $t, $u);

    */
    require_once("html/it.php");
    $tpl    = new html_template_it("./");
    //读取模板文件           
    $tpl->setroot("./");
    $tpl->loadtemplatefile("listcart.html", true, true);
    require_once "../classes/cart.php" ;
    $cart = new cart   ;
//    $cart->adddata($rst);
    $i=count($_post[lines])    ;
    if($_post["emptyall"]==true)
    {
        //如果清空条件为真
        $cart->emptyall()    ;
    }else{
        //如果用户提交更新
        if( $i > 0)
        {
            //如果提交过来的数据大于一个商品
            $adddata = $_post[lines]    ;
            foreach($adddata as $key=>$val)
            {
                if($val["del"]==true)
                {    
                    $cart->emptyone($key)        ;
                    unset($adddata[$key])            ;
                }
            }
            $cart->adddata($adddata)    ;
        }
    }
    $dat = $cart->getdata();
    if(count($dat) > 0)
    {
        foreach($dat as $key=>$val)
        {        
            $tpl->setcurrentblock("lines") ;
    //        $tpl->setvariable($lan) ;
            $tpl->setvariable("id", $key) ;        
            $tpl->setvariable("i" , $key) ;    
            $tpl->setvariable("totalcount" , $cart->getsortcount()) ;
            $tpl->setvariable("totalmoney" , $cart->gettotalcost()) ;
            $tpl->setvariable($val) ;    
            $tpl->parsecurrentblock("lines") ;    
        }
    }
    //替换模板页面中的标记
    $tpl->setcurrentblock("page") ;
    if($key==false)$key=0;
    $tpl->setvariable("i" , $key) ;    
    $tpl->setvariable("mytitle", "我的购物篮") ;    
//    $tpl->setvariable($language->getlanurl()) ;    
    $tpl->parsecurrentblock("page") ;  

    //显示页面
    $tpl->show();

ob_end_flush();
?>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 使用方法-PHP教程,PHP应用
分享到: 更多 (0)

相关推荐

  • 暂无文章