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>
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);
?>
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');
}
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)) {