【发布时间】:2020-02-28 10:03:33
【问题描述】:
我正在尝试在我的 CodeIgniter 项目中使用 JQuery、Noty 获取通知。
我使用了以下脚本代码
<script type="text/javascript">
$(document).ready(function() {
<?php
if (!empty($noti)) {
foreach ($noti as $ns) {
$date = new DateTime($ns->increment_date);
}
}
?>
noty({text: 'The Increment Date of', layout: 'center', closeWith: ['click', 'hover'], type: 'success'});
});
</script>
型号
<?php
class Welcome_Model extends CI_Model {
function __construct() {
parent::__construct();
}
function increment_date(){
$this->db->select('title, initials, last_name, increment_date');
$this->db->from('tbl_officer');
$this->db->where('tbl_officer.status=1 and str_to_date(concat(increment_date,'-',year(curdate())),"%d-%b-%Y")
between curdate() and curdate() + interval 30 day');
$query= $this->db->get();
if($query->num_rows()>0){
return $query->result();
}
}
}
代码运行良好,并发出通知“增量日期”。但我想在本文末尾排除$ns->increment_date 的值。当我在文本中将$ns->increment_date 添加为'The Increment Date of <?=$ns->increment_date?>' 时,通知不起作用。
可能出了什么问题?任何人都可以帮忙吗?
【问题讨论】:
-
将
php块移到 JS 块之前。 -
@ascsoftw。但是没用
-
检查控制台查看错误。检查视图源的外观。
-
@ascsoftw。如果我使用 'The Increment Date of increment_date ?>',代码会输出 increment_date 的增量日期?>
-
请看下面的答案。
标签: jquery mysql codeigniter