如何在连续的数据库整体上交替浮动?
正如您在上面的链接中看到的,有几个“孩子” ',每一项的信息都是从数据库中获取的。
我想让每个交替图像向左浮动,以便图像向左,然后向右,然后向左等等。目前它们都向左浮动。这就是我到目前为止所拥有的:
<?php
$query="SELECT id, title, text, media, media2, thumb, deleted FROM kids ORDER BY id DESC";
$result=mysql_query($query);
while($row = mysql_fetch_array($result)){
if($row['deleted'] == 0) {
echo '<div id="'.$row['title'].'">';
echo '<img src="images/'.$row['media'].'" class="floatLeftClear" id="border" />';
if($row['media2'] != "") {
echo '<img src="images/'.$row['media2'].'" class="floatLeftClear" id="border" />';
}
echo '<p id="text">';
echo '<span class="kisstitle">'.$row['title'].'</span><br>';
echo $row['text'];
echo '</p>';
echo ' <p align="center" id="spererater"><img src="images/seperater.jpg" width="900" height="5" /><a href="index2.php?op=The Kids#top">Top</a><br /></p>';
}}
?>
我尝试检查ID,如果是偶数,则向左浮动,如果是奇数,则向右浮动,但我不知道该怎么做,而且ID可能并不总是偶数/奇数交替所以如果可能的话我宁愿找到不同的解决方案。
As you can see on the above link there are several 'kids', the information for each one is grabbed from a database.
I want to make each alternating image float to the left, so that the images go left, then right, then left etc. At the moment they all float left. This is what I have so far:
<?php
$query="SELECT id, title, text, media, media2, thumb, deleted FROM kids ORDER BY id DESC";
$result=mysql_query($query);
while($row = mysql_fetch_array($result)){
if($row['deleted'] == 0) {
echo '<div id="'.$row['title'].'">';
echo '<img src="images/'.$row['media'].'" class="floatLeftClear" id="border" />';
if($row['media2'] != "") {
echo '<img src="images/'.$row['media2'].'" class="floatLeftClear" id="border" />';
}
echo '<p id="text">';
echo '<span class="kisstitle">'.$row['title'].'</span><br>';
echo $row['text'];
echo '</p>';
echo ' <p align="center" id="spererater"><img src="images/seperater.jpg" width="900" height="5" /><a href="index2.php?op=The Kids#top">Top</a><br /></p>';
}}
?>
I tried to check the ID, if even, float left, if odd, float right, but I couldn't work out how to do it, plus the ID may not always be even / odd alternating so I'd rather find a different solution if possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用计数器变量,每次循环一个项目时加一 - 并将该计数器与模一起使用,以确定您是在偶数行还是奇数行:
Use a counter variable, increment by one each time you're looping over an item -- and use that counter with a modulo, to determiner whether you are on an even or odd line :
添加一个计数器。循环之前
$i = 0;
和循环内部$i++
,if ($i % 2 == 0) { // odd } else {// Even }
Add a counter. Before loop
$i = 0;
and inside loop$i++
,if ($i % 2 == 0) { // odd} else {// even}