php原生 出现要输出两条数据的情况的解决办法

<li>
	<div class="pbox">
		<a class='ajax' href="products/pro1.html" title="2016秋季九款英伦风男童格子衬衫 特价品牌童装">
			<div class="pic"><img src="images/pic5.jpg" height="237" width="248" alt=""></div>
				<h6>2016秋季九款英伦风男童格子衬衫 特价品牌童装</h6>
		</a>
	</div>
	<div class="pbox">
                <a class='ajax' href="products/pro1.html" title="2016秋季九款英伦风男童格子衬衫 特价品牌童装">
			<div class="pic"><img src="images/pic5.jpg" height="237" width="248" alt=""></div>
				<h6>2016秋季九款英伦风男童格子衬衫 特价品牌童装</h6>
		</a>
	</div>
</li>
   <li>
	<?php 
            $sql="select * from product where active=1 and type_id in (select id from product_type where type_name='王子童装')";
            $sql1="select COUNT(*) from product where active=1 and type_id in (select id from product_type where type_name='王子童装')";
            mysql_query("set names utf8");
            $result=mysql_query($sql);
            $result1=mysql_query($sql1);
            $row1=mysql_fetch_array($result1);
            $i = 0;
            while($row=mysql_fetch_array($result)){
                $i++;
                $p_id = $row['id'];
                $title=$row['product_title'];
                $param=$row['param'];
                $p_array=split('[|]',$param);
                if(utf8strlen($p_array[2])>108)
                    {
                       $p_array[2]=utf8substr($p_array[2],0,108)."...";
                    }
                    ?>
		<div class="pbox">
			<a class='ajax' href="p_show.php?id=<?php echo $p_id;?>" title="<?php echo $title;?>">
				<div class="pic"><img src="<?php echo $p_array[0];?>" height="237" width="248" alt=""></div>
					<h6><?php echo $p_array[1];?></h6>
			</a>
		</div>
							
	<?php
	        if ($i == $row1[0]){
                   echo "</li>";
                }elseif($i%2==0){
                    echo "</li><li>";
                }
             }
        ?>

方法一:根据定义的变量i 判断是否为最后一条记录 是的话输出结束标签  否的话输出中间标签

方法二 : for循环  for($i=0;$i<count(总记录数); $i=$i+2){echo $row[$i];echo $row[$i+1];}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章