2

我有一个简单的搜索引擎,它在一个带有 CSS 格式的表格中回显结果,这工作正常,但是,我现在想在每 10 个结果后回显一个不同的图像。

感谢任何可以帮助我的人,因为我已经坚持了几个小时!

这是我的回声输出代码:

echo "<table width='50%' style='border-bottom:1px solid #000000;'";
echo "<tr>";
echo "<td>";
echo "<div id='page-wrap'>";
echo "<div class='discounted-item freeshipping'>";

echo "<a href='./img/users/" . $row['category'] . "/" . $row['username'] . "/" . $row['filename'] . "' rel='lightbox'><img src=\"./img/users/" . $row['category'] . "/" . $row['username'] . "/" . $row['filename'] . "\" alt=\"\" width='20%' height='98%' /></a>";


echo "<div class='reasonbar'><div class='prod-title' style='width: 70%;'>" .$row['fname'] . "</div><div class='reason' style='width: 29%;'><b>". $row['firstname'] . " " . $row['surname'] ."</b></div></div>";

echo "<div class='reasonbar'><div class='prod-title1' style='width: 70%;'>" . $row['lname'] . "</div><div class='reason1' style='width: 29%;'>Category: ". $row['category'] . "</div></div>";

echo "<div class='reasonbar'><div class='prod-title2' style='width: 70%;'>Contact:" . $row['contact'] . "</div><div class='reason2' style='width: 29%;'>Price: &pound;". $row['price'] . "</div></div>";


echo "</td>";
echo "</tr>";
echo "</td>";
echo "</tr>";
echo "</table>";
}

}

else
    echo "No results found for \"<b>$search</b>\"";
4

1 回答 1

2

您可以使用模数运算符来确定...

if ( ! ($i % 10)) {
    // Alternate.
}

如果您没有可用的计数器变量,只需在循环之外声明一个变量并将其设置为0并为每次迭代递增。

于 2012-09-03T23:49:25.670 回答