0

i have a litte problem! i want to fetch the last 3 rows from my mysql database.. (works)

<?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
}
?>

my problem is the html layout! i have 3 div boxes wich i will float..

    <div class="one-of-three">
        [...]
    </div>
    <div class="two-of-three">
        [...]
    </div>
    <div class="three-of-three">
        [...]
    </div>

but my result gives me

    <div class="one-of-three">
        [...]
    </div>
    <div class="one-of-three">
        [...]
    </div>
    <div class="one-of-three">
        [...]
    </div>

i tried different things but i dont how it works :( you can give me a hint?

4

2 回答 2

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">
于 2012-05-27T09:33:45.477 回答
0

你可能应该得到一个数组$numbers = array('one', 'two', 'three');。然后有一个变量$i = 0;并在循环中增加它。第一行应该是这样的:<div class="<?php echo $numbers[$i++]; ?>-of-three">.

于 2012-05-27T09:25:24.983 回答