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];}

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