0
我有一個從數據庫中提取的俱樂部列表,然後使用下面的代碼將它們按字母順序排列,並在它們上面添加第一個字母的標題。Zend Framework按字母順序排列的列表,新條目沒有按字母順序排列
<?php
$previousLetter = false;
?>
<?php
$i=1; // have a counter variable
foreach($this->clubs as $clubs) : ?>
<?php
$firstLetter = substr($clubs->club_name, 0, 1);
if ($firstLetter != $previousLetter) {
if($i==1){
echo "<div class='left_class'>"; // open left div
}
?>
<h3 id="club-link-header"><u><?php echo $firstLetter; ?></u></h3>
<?php } ?>
<a id="club-link" href="<?php echo $this->url(array('controller' => 'club-description', 'action' => 'index', 'club_id' => $clubs->id));?>"><br />
<?php echo $this->escape($clubs->club_name);?></a>
<?php $previousLetter = $firstLetter; ?>
<?php
if($i==25){
echo "</div>"; //close left div
echo "<div class='right_class'>"; // open right div
}
if($i==50){
echo "</div>"; //close right div
}
$i++; // increment the counter variable for each loop
endforeach;
?>
的問題是,當我添加一個新進入它不是alphabetised數據庫,它被添加到列表的末尾。
只需添加一個'ORDER BY'子句到SQL查詢。 – dbrumann
我試過了,它沒有工作,它會工作,如果我沒有格式的列表我有..這裏是控制器,我初始化ORDER BY - > http://pastebin.com/XrPMEQD0 – Rex89