简体   繁体   English

CakePHP MySQL选择每月的一天

[英]CakePHP mysql select day of month

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. 我只会从MySQL中选择一个月中的某天,但会给我写一个错误。

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 的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? 你能告诉我哪里有错误吗?

Try to debug $data in your view: 尝试在您的视图中调试$ data

debug($data);

If you call the find method, you'll usually get a multi dimensional array. 如果调用find方法,通常会得到一个多维数组。

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! 祝好运!

You do not have the index 'den', but you try to use it. 您没有索引“ den”,但是您尝试使用它。 (calendar.ctp, line 4). (calendar.ctp,第4行)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM