2017-04-17 9 views
2

私は 'Sr.によってテーブルを注文したいと思います。いいえ 'を降順に並べ替えます。私はデータベースからではなく、PHPが生成されたので、どうやっているのか分かりません。CakePHP管理パネルの注文

<table> 
    <tr> 
     <th>Sr. No</th> 
     <th>Naslov</th> 
    </tr> 
    <?php $counter = 0; foreach($posts as $post) : $counter++; ?> 
    <tr> 
     <td><?php echo $counter?></td> 
     <td><?php echo $this->Html->link($post['Post']['title'], array('controller' => 'Posts', 'action'=> 'view', $post['Post']['id']), array('class' => 'link')); ?></td> 
    </tr> 
    <?php endforeach; ?> 
    <?php unset($post); ?> 
</table> 
+0

$ postsはどこに定義されていますか? –

答えて

1

は、あなたは以下のような順に$counterを行う必要があります -

<?php $counter = count($posts); foreach($posts as $post) : $counter--; ?> 
    <tr> 
     <td><?php echo $counter?></td> 
     <td><?php echo $this->Html->link($post['Post']['title'], array('controller' => 'Posts', 'action'=> 'view', $post['Post']['id']), array('class' => 'link')); ?></td> 
    </tr> 
<?php endforeach; ?> 

あなたはまた、クエリで、その後順にNaslovは(投稿を意味する)したい場合は、ORDER BY <column name like id> DESC

をしなければなりません適用方法を確認してください。DESC: - https://stackoverflow.com/a/9837302/4248328

例: - $this->Post->find('all', array('order' =>array('Post.id DESC')));

関連する問題