我不完全确定如何解释这一点,但基本上我有一个 x 变量等于数据库中的行数,每次它等于或小于 4 时,运行一段代码。
假设我有 5 行,我想执行两次代码,因为 x 等于 4 一次然后等于 1。如果我有 6 行 (4+2) 7 行 (4+3) 或 8 行 (4 +4)。
然后,当我达到 9 行 (4+4+1) 时,它将执行三次代码。ETC...
我试图运行的代码是一段 HTML,里面有更多的 PHP。<ul>
如上所述,每次行数等于或小于 4 时,我想在其中创建一个新的带有上述代码的代码。
现在的代码:
<div class="row-fluid well">
<?php
$num_rows = mysql_num_rows($result);
if ($num_rows <= 4) {
?>
<ul class="minigames">
<?php
while ($row = mysql_fetch_array($result)) {
echo "<li class='span3'>";
if (logged_in() === false && !empty($row['app_about']) === true && strlen($row['app_about']) <= 100) {
echo "<a href='#!' class='thumbnail minigamedesc' title='" . $row['app_name'] . "' data-content='" . $row['app_about'] . "<br /><br /><center><a href=\"./games.php?play_error#library\" class=\"btn btn-info\"><i class=\"icomoon-white icomoon-screen\"></i> Play in browser</a></center>'>";
} else if (logged_in() === false && !empty($row['app_about']) === true && strlen($row['app_about']) >= 101) {
$app_about = substr(strip_tags($row['app_about']), 0, 100);
echo "<a href='#!' class='thumbnail minigamedesc' title='" . $row['app_name'] . "' data-content='" . $app_about . "<a href=\"./games.php?play_error#library\">...</a><br /><br /><center><a href=\"./games.php?play_error#library\" class=\"btn btn-info\"><i class=\"icomoon-white icomoon-screen\"></i> Play in browser</a></center>'>";
} else if (!empty($row['app_about']) === true && strlen($row['app_about']) <= 100) {
echo "<a href='#!' class='thumbnail minigamedesc' title='" . $row['app_name'] . "' data-content='" . $row['app_about'] . "<br /><br /><center><a href=\"./play.php?app=" . $row['app_id'] . "\" class=\"btn btn-info\"><i class=\"icomoon-white icomoon-screen\"></i> Play in browser</a></center>'>";
} else if (!empty($row['app_about']) === true && strlen($row['app_about']) >= 101) {
$app_about = substr(strip_tags($row['app_about']), 0, 100);
echo "<a href='#!' class='thumbnail minigamedesc' title='" . $row['app_name'] . "' data-content='" . $app_about . "<a href=\"./play.php?app=" . $row['app_id'] . "\">...</a><br /><br /><center><a href=\"./play.php?app=" . $row['app_id'] . "\" class=\"btn btn-info\"><i class=\"icomoon-white icomoon-screen\"></i> Play in browser</a></center>'>";
} else {
echo "<a href='#!' class='thumbnail minigamedesc' title='" . $row['app_name'] . "' data-content='Nothing to see here, yet ! <br /><br /><center><a href=\"./play.php?app=" . $row['app_id'] . "\" class=\"btn btn-info\"><i class=\"icomoon-white icomoon-screen\"></i> Play in browser</a></center>'>";
}
?>
<img src="<?php echo $row['app_preview']; ?>">
<div class="minigames-caption">
<h4><?php echo $row['app_name']; ?></h4>
<p>By <?php echo $row['app_dev']; ?>.</p>
</div>
</a>
<?php
echo "</li>";
}
?>
<?php
}
?>