仅查看当前月份的FullCalendar

Good afternoon friends, how do I display only the names of the events by the month, not the year as shown in the code below. Example, has 04 user in month 09.

<?php

//Database
$data = array();


$link = mysqli_connect("localhost", "root", "", "agenda");

mysqli_set_charset($link, 'utf8');

if (!$link) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}

$query = "SELECT * FROM clientes";

if ($result = $link->query($query)) {

    /* fetch object array */
    while ($obj = $result->fetch_object()) {
        $data[] = array(
            'id' => $obj->id,
            'title'=> $obj->title,
            'start'=> $obj->start
        );
    }

    /* free result set */
    $result->close();
}

mysqli_close($link);

?>

<script>

    $(document).ready(function() {

        $('#clientes').fullCalendar({
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,basicWeek,basicDay'
            },
            defaultDate: '<?php echo date('Y-m-d');?>',
            editable: true,
            eventLimit: true, // allow "more" link when too many events
            events : <?php echo json_encode($data);?>
        });

    });

</script>

Sample output

Database schema

This is the code of the second block of the same result.

<?php

//Database
$data = array();

$link = mysqli_connect("localhost", "root", "", "agenda");

mysqli_set_charset($link, 'utf8');

$month = date('n');
$year = date('Y');
$query = "SELECT * FROM clientes WHERE MONTH(`start`) = $month AND YEAR(`start`) = $year";


if ($result = $link->query($query)) {

    /* fetch object array */
    while ($obj = $result->fetch_object()) {
        $data[] = array(
            'id' => $obj->id,
            'title'=> $obj->title,
            'start'=> $obj->start
        );
    }

    /* free result set */
    $result->close();
}

mysqli_close($link);

?>

enter image description here

If the code is so, he warns "Invalid Data":

$month = date('n');
$year = date('Y');
if (is_int($month) && is_int($year)) {
    $query = "SELECT * FROM clientes WHERE MONTH(`start`) = $month AND YEAR(`start`) = $year";
} else {
    die ('Invalid data');
}

2个回答



我得到问题制作下一个让路。</ p>

按如下方式放置选择。</ p>

  $ query =“select id,title,concat_ws(' - ',year(now()),MONTH(start),DAY(start))AS从clientes开始”;

</ code> </ pre>
</ div>

展开原文

原文

I got the Problem Making Next make way.

Placing the select as follows.

$query = "select id, title,  concat_ws( '-', year(now()), MONTH(start), DAY(start)) AS start from clientes";

You can use the SQL to limit the rows returned like so:

SELECT * FROM clientes WHERE MONTH(`start`) = 4 AND YEAR(`start`) = 2016;

To code it to work with variables submitted from a form:

$month = filter_var($_POST['month'], FILTER_VALIDATE_INT);
$year = filter_var($_POST['year'], FILTER_VALIDATE_INT);
if (is_int($month) && is_int($year)) {
    $query = "SELECT * FROM clientes WHERE MONTH(`start`) = $month AND YEAR(`start`) = $year";
} else {
    die ('Invalid data');
}

Never submit data that hasn't been escaped, validated or sanitized to the database. In this case I used validation because it ensures only integers will be used in the query. You may also use prepared statements.

START is a reserved word in MySQL, which is why the ` (backtick)s are required.

To get the current month and year from the server and use it in your code:

$month = date('n');
$year = date('Y');
$query = "SELECT * FROM clientes WHERE MONTH(`start`) = $month AND YEAR(`start`) = $year";

if ($result = $link->query($query)) {
duanhan5388
duanhan5388 所以请帮助我,因为我无法正确编辑我的代码。
大约 4 年之前 回复
dongyan1841
dongyan1841 使用第三个块中的代码,将其放在代码中if语句的正上方。 复制三行,一行以$ month开头,一行以$ query开头,然后将它们粘贴到代码中有$ query的位置。 对不起,我没时间聊天。
大约 4 年之前 回复
douzhi7451
douzhi7451 我把第二块的代码。 从同样的结果。 输入此聊天:chat.stackexchange.com/rooms/45535/fullcalendar
大约 4 年之前 回复
doukui4836
doukui4836 我做了上面的例子并给出了“无效日期”和通知:未定义的索引:第40行的月份和通知:未定义的索引:41年的年份
大约 4 年之前 回复
douhu7807
douhu7807 chat.stackexchange.com/rooms/45535/fullcalendar
大约 4 年之前 回复
doukuanghuan7582
doukuanghuan7582 让我们聊聊这个问题@ user2182349,以便能够解决这个问题。
大约 4 年之前 回复
doujian3401
doujian3401 相同的结果@ user2182349
大约 4 年之前 回复
dsgdhf5674
dsgdhf5674 我没有,你可以帮助我在我自己的代码看起来像,请。
大约 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐