Reputation: 11
I hope to write correctly because I'm not very good in English. I would select only the day of the month from MySQL but writes me an error.
CONTROLLER
$fields = array('id', 'nazov','DAY(datum) AS day','datum');
$data = $this->udalost->find('all',array('conditions'=>'MONTH(datum) = '.$month.' AND YEAR(datum) = '.$year,'fields'=>$fields,'order'=>'datum ASC'));
$this->set('data',$data);
VIEW
echo $data["day"];
ERROR
Notice (8): Undefined index: day [APP\views\udalosti\calendar.ctp, line 4]
MySQL
CREATE TABLE `udalost` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`nazov` VARCHAR(255) DEFAULT NULL,
`datum` datetime DEFAULT NULL,
`text` text,
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM
Can you tell me where I have error?
Upvotes: 0
Views: 1143
Reputation: 626
You do not have the index 'den', but you try to use it. (calendar.ctp, line 4).
Upvotes: 0
Reputation: 129
Try to debug $data in your view:
debug($data);
If you call the find method, you'll usually get a multi dimensional array.
Also write the condition like this:
$data = $this->udalost->find('all',
array(
'conditions'=> array(
'MONTH(datum) = '.$month,
'YEAR(datum) = '.$year
),
'fields'=>$fields,
'order'=>'datum ASC'
)
);
Good luck!
Upvotes: 1