I have trouble with this code in cakephp for a sql query
Here my code in RankingsController.php
<?php
class RankingsController extends AppController {
public $helpers = array('Html', 'Form', 'Session');
public $components = array('Session');
public function index() {
$this->Ranking->virtualFields += array(
'totalpoints' => 0);
$rankings = $this->Ranking->query("
select turnierranks.teilnehmer_id as teilnehmer_id,
teilnehmers.nachname, teilnehmers.vorname,
sum(pointtab.points) as totalpoints
from turnierranks, pointtab, turniers, teilnehmers
where
turnierranks.turnier_id = turniers.id and
turniers.turnierkategorie = pointtab.kategorie and
turnierranks.rank = pointtab.rank and
teilnehmers.id = teilnehmer_id
group by teilnehmer_id, teilnehmers.nachname, teilnehmers.nachname
order by totalpoints desc");
debug($rankings);
}
}
debug (rankings$) show the right querydata
but in views/Rankings/index.cpt i get the error
Undefined variable: rankings [APP/View/Rankings/index.ctp, line 12] and the same error for the next line
LINE 12: <?php debug($rankings); ?>
<?php foreach ($rankings as $ranking): ?>
in Model ranking.php
<?php
class Ranking extends AppModel {
public $useTable = false;
}
whats is wrong with the $rankings variable array?