码迷,mamicode.com
首页 > Web开发 > 详细

php练习:每5个商品一排

时间:2016-07-17 10:06:22      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:

 

老板说:

我要一行5个商品,每个长得都不一样

技术分享

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>练习</title>
<style>
    li{list-style: none;}
    .slide-content li{float:left;width:100px;height:100px;border:1px solid #000;margin:5px;line-height: 100px;color:#000;text-align: center;}
    .li-1{background:red;}
    .li-2{background:yellow;}
    .li-3{background:blue;}
    .li-4{background:green;}
    .li-5{background:gray;}
</style>
</head>
<body>

<?php
//商品组至少5个噢
$items=array(
    array("name"=>"product1","price"=>10),
    array("name"=>"product2","price"=>20),
    array("name"=>"product3","price"=>30),
    array("name"=>"product4","price"=>40),
    array("name"=>"product5","price"=>10)
);
//一行显示5个

    $li_n=5;
    //宝贝数
    $p_num=count($items)+1;    
    //循环的ul数,cei(1.5)=2
    $ul_n=ceil($p_num/$li_n);    
for($i=1;$i<$ul_n;$i++){    
    $li_nav=1;    
    echo ‘<ul class="slide-content">‘;
            foreach($items as $key => $item){

                /*listart*/
                $s_n=$key+1;
                $end_q=$i*$li_n;
                $star_q=$end_q-$li_n;

                /*1-5,5-10,10-15等,li_nav每次从1开始*/
                if($s_n>$star_q and $s_n<=$end_q){
                    echo ‘<li class="li-‘.$li_nav.‘">‘.$item[‘name‘].‘</li>‘;
                    $li_nav++;
                }    
                /*liend*/
            }    
echo ‘</ul>‘;
    }
?>


</body>
</html>

 技术分享

php练习:每5个商品一排

标签:

原文地址:http://www.cnblogs.com/tinyphp/p/5661105.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!