我有一个小问题!我想从我的mysql数据库中获取最后3行..(工作)
<?php
$sql = "SELECT id,title,description FROM news ORDER BY `id` DESC LIMIT 0, 3";
$result = mysql_query($sql);
while ($list = mysql_fetch_assoc($result))
{
?>
<div class="one-of-three">
<div class="box">
<h2><?PHP echo ($list['id']);?> <?PHP echo (htmlentities($list['title'],ENT_QUOTES,'UTF-8'));?></h2>
<div class="content clearfix">
<p><?PHP echo (htmlentities($list['description'],ENT_QUOTES,'UTF-8'));?></p>
</div>
</div>
</div>
<?php
}
?>
我的问题是html布局!我有3个div盒,我会漂浮..
<div class="one-of-three">
[...]
</div>
<div class="two-of-three">
[...]
</div>
<div class="three-of-three">
[...]
</div>
但我的结果给了我
<div class="one-of-three">
[...]
</div>
<div class="one-of-three">
[...]
</div>
<div class="one-of-three">
[...]
</div>
我尝试了不同的东西,但我不知道它是如何工作的:( 你可以给我一个提示吗?
答案 0 :(得分:0)
你应该得到一个数组$numbers = array('one', 'two', 'three');
。然后有一个变量$i = 0;
并在循环中递增它。第一行应该是:<div class="<?php echo $numbers[$i++]; ?>-of-three">
。
答案 1 :(得分:0)
<?php
$n = array(1 => 'one', 2 => 'two', 3 => 'three');
while ($list = mysql_fetch_assoc($result)) {
?>
<div class="<?php echo $n[$list['id']]; ?>-of-three">