Home > php教程 > php手册 > 使用方法

使用方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-21 09:11:47
Original
928 people have browsed it

这是我当时写的一个列出所有购物车中的清单的程序,各位可自己根据需要改写一下
    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();
?>



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template