如果我理解正确,您想显示之前显示次数少于 100 次的所有横幅?
如果这是正确的,您可以将其添加到您的WHERE
子句中:
$bannerResult = mysql_query("SELECT * FROM table WHERE page='cat' WHERE `COUNT` < 100");
要全部更新它们,您可以在显示每个单独的横幅时运行查询,或者“记录”每个横幅id
并在最后运行单个查询,例如:
$ids = array();
foreach($bannerGroups[0] as $ban) {
$ids[] = $ban['ID']; // record the ID; don't know how Banner
// class works, assuming uses indexes; maybe ID() method?
echo '<li class="right1">'.$ban->html().'</li>';
}
...
mysql_query('UPDATE table SET `COUNT` = `COUNT` + 1 WHERE ID IN (' . join(',', $ids) . ')');
更新:
根据评论,您的Banner
班级没有检索单个横幅的ID
. 在这种情况下,您可以ID
在构建横幅数组时记录这些值:
$ids = array();
while($row=mysql_fetch_assoc($bannerResult)) {
$banners[] = new Banner($row);
$ids[] = $row['ID']; // record the ID
}
// update the `count` on each record:
mysql_query('UPDATE table SET `COUNT` = `COUNT` + 1 WHERE ID IN (' . join(',', $ids) . ')');