2010-08-16 48 views
1

目前即時通訊具有這種用於顯示我的statusmessages:PHP:而()最新更大的字體大小

<?php 
while($showSe = mysql_fetch_array($stringUSS)) { ?> 

    <strong style="font-size: 12px;"><?php get_day_name($showSe["date"]); get_time($showSe["date"]); ?> </strong><br> 
    <span style="font-size: 20px; text-align: center; margin: 10px;"><?php echo $showSe["status"]; ?></span> 
    <hr> 
<?php } ?> 

現在顯示一切從ID數據庫秩序。我現在想要做的是第一個/最新的,應該有font-size:18px;而其餘的有12px;

回答

1

你可以使用一個計數器或標誌,表示第一次迭代:

$counter = 0; 
while ($showSe = mysql_fetch_array($stringUSS)) { 
    $fontSize = ($counter === 0) ? 18 : 12; 
?> 
<strong style="font-size: <?php echo $fontSize;?>px;"><?php get_day_name($showSe["date"]); get_time($showSe["date"]); ?> </strong><br> 
<span style="font-size: 20px; text-align: center; margin: 10px;"><?php echo $showSe["status"]; ?></span> 
<?php 
    $counter++; 
} 

另一種方法是使用純CSS:把你的列表中的項目(如OL),並使用ol > li:first-child > strong選擇第一LISTRONG元素:

ol > li > strong { 
    font-size: 12px; 
} 
ol > li:first-child > strong { 
    font-size: 18px; 
} 
+0

或者你可以只是做'$字號= 18'外循環,然後將其重置爲12後的第一個結果行一直輸出。但是,如果OP決定多條「第一」線路需要進行embigenation處理,那麼使用櫃檯會更加靈活。 – 2010-08-16 21:08:21