我正在尝试在存储的数据库中回显3个位置,用html分隔符打破它们,然后再回显3个地方,然后是html分隔符,依此类推。目前我的代码只打印了一个地方,然后是分隔符。有这么简单的方法吗?
<?
include_once "connect_to_mysql.php";
$sql = mysql_query("SELECT `p_id`, `pname`, `address`, `country`, `type` FROM places WHERE category='ecodo'");
$count = mysql_num_rows($sql);
while($row = mysql_fetch_array($sql)){
$p_id = $row["p_id"];
$pname = $row["pname"];
$address = $row["address"];
$country = $row["country"];
$type = $row["type"];
echo '
<div class="col-md-3 col-sm-6 md-margin-bottom-40">
<div class="easy-block-v2">
<img alt="" src="placeFiles/'.$p_id.'/pic1.jpg">
<h3>'.$pname.'</h3>
<ul class="list-unstyled">
<li><span class="color-green">Type: </span>'.$type.'</li>
<li><span class="color-green">Address: </span>'.$address.'</li>
<li><span class="color-green">Country:</span>'.$country.'</li>
</ul>
<a class="btn-u btn-u-sm" href="place_profile.php?p_id='.$p_id.'">See More</a>
</div>
</div>
<!-- Divider -->
<div class="clearfix margin-bottom-20"><hr></div>
<!-- Easy Blocks v2 -->
<div class="row">';
}
?>
答案 0 :(得分:3)
一个简单的计数器变量应该可以工作。
$counter = 0;
while ($row = ... ) {
if ( ! $counter++ % 3) {
echo 'Divider';
}
// Rest of code
}