我刚刚开始使用 PHP 和 mySQL(现在大约 4 天)并且一直在尝试找到解决这个问题的方法......
我有一组从 mySQL 数据库返回的项目。我让这些流入一组 4 个“ul”列和一类“模型”,它将结果数除以 4 并返回“li”,无法弄清楚为什么我在结尾。我曾尝试将“ul”放入 foreach 语句中,但这也没有返回所需的结果。
谢谢你的帮助。
这是php:
<grid>
<ul class="models">
<?php
$c = count($model);
$s = ($c / 4); // change 4 to the number of columns you want to have.
$i=1;
foreach ($model as $models): ?>
<li>
<a href="model/?id=<?php htmlout($models['sn']); ?>" class="id<?php htmlout($models['sn']); ?>">
<div class="<?php htmlout($models['callout']); ?>"></div>
<div id="description">
<h2><?php htmlout($models['firstname']); ?> <?php htmlout($models['lastname']); ?>
</h2>
<h3><span class="number">40</span> photo sets</h3>
<h3><span class="number">756</span> images</h3>
<p><?php htmlout($models['rightstext_left']); ?>
<?php htmlout($models['firstname']); ?>
<?php htmlout($models['rightstext_right']); ?>
</p>
</div>
</a>
</li>
<?php if($i != 0 && $i % $s == 0)
{
?>
</ul>
<ul class="models">
<?php
}
$i++; ?>
<?php endforeach; ?>
</ul>
</grid>
的HTML
<grid>
**excluded**
<ul class="models">
<li>
<a href="model/?id=AZWW5RJE" class="idAZWW5RJE">
<div class="exclusive"></div>
<div id="description">
<h2>Model 19</h2>
<h3><span class="number">1</span> attribute</h3>
<h3><span class="number">6</span> attributes</h3>
<p>textleft name textright</p>
</div>
</a>
</li>
<li>
<a href="model/?id=AZWW5RJE" class="idAZWW5RJE">
<div class="exclusive"></div>
<div id="description">
<h2>Model 19</h2>
<h3><span class="number">1</span> attribute</h3>
<h3><span class="number">6</span> attributes</h3>
<p>textleft name textright</p>
</div>
</a>
</li>
<li>
<a href="model/?id=AZWW5RJE" class="idAZWW5RJE">
<div class="exclusive"></div>
<div id="description">
<h2>Model 19</h2>
<h3><span class="number">1</span> attribute</h3>
<h3><span class="number">6</span> attributes</h3>
<p>textleft name textright</p>
</div>
</a>
</li>
<li>
<a href="model/?id=AZWW5RJE" class="idAZWW5RJE">
<div class="exclusive"></div>
<div id="description">
<h2>Model 19</h2>
<h3><span class="number">1</span> attribute</h3>
<h3><span class="number">6</span> attributes</h3>
<p>textleft name textright</p>
</div>
</a>
</li>
<li>
<a href="model/?id=AZWW5RJE" class="idAZWW5RJE">
<div class="exclusive"></div>
<div id="description">
<h2>Model 19</h2>
<h3><span class="number">1</span> attribute</h3>
<h3><span class="number">6</span> attributes</h3>
<p>textleft name textright</p>
</div>
</a>
</li>
</ul>