我有一个工作foreach循环中我观点:CakePHP的PHP MySQL的
<? foreach($words as $word): ?>
<td><?= $word['Word']['category'] ?></td>
<? endforeach; ?>
功能在我控制器:
public function index()
{
$this->Paginator->settings = array(
'conditions' => array('Word.role' => CakeSession::read("Auth.User.username")),
'limit' => 100
);
$data = $this->Paginator->paginate('Word');
$this->set('words', $data);
}
的foreach
显示所有类别,但我想说明在我的列表中只有唯一的类别。你如何做到这一点?
您可以在查询中使用['GROUP BY'(https://dev.mysql.com/doc/refman/5.5/en/group-by-handling.html)或发现的情况下, cakePHP –