我有一个问题! 我想从我的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>
我尝试了不同的东西,但我不知道它是如何工作的:(你能给我一个提示吗?
您可能应该得到一个数组$numbers = array('one', 'two', 'three');
。然后有一个变量$i = 0;
并在循环中递增它。然后第一行应该是这样的:<div class="<?php echo $numbers[$i++]; ?>-of-three">
。
<?php
$n = array(1 => 'one', 2 => 'two', 3 => 'three');
while ($list = mysql_fetch_assoc($result)) {
?>
<div class="<?php echo $n[$list['id']]; ?>-of-three">