2
I need to create an agenda.. I have a datepicker and a fixed table beside with schedule that start from 08:00am until 19:00pm and when I click on a datepicker day it returns to me all the queries of that day in the table beside in their respective schedules.. If you have an open schedule, it should be null.. My problem is that I am not able to manipulate the data that ajax returns me (json) I am able to get the data in array but I cannot place it in its proper place of table..
follows my codes:
javascript:
<script>
$(document).ready(function() {
$('#datepicker').datepicker({
dateFormat: 'yy-mm-dd',
dayNames: ['Domingo','Segunda','Terça','Quarta','Quinta','Sexta','Sábado'],
dayNamesMin: ['D','S','T','Q','Q','S','S','D'],
dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','Sáb','Dom'],
monthNames: ['Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez'],
nextText: 'Próximo',
prevText: 'Anterior',
inline: true,
onSelect: function () {
var date = $("#datepicker").val();
$.ajax({
type: "POST",
url: "retornar_data.php",
data: { date: date },
success: function(data) {
$.each($.parseJSON(data), function(chave,valor){
console.log(data);
var lista = '<table border="1">'
lista += '<th> Hora </th>';
lista += '<th> Data </th>';
lista += '<th> Descrição </th>';
lista += '<tr>'
lista += '<td>8:00</td>'
lista += '<td> </td>'
lista += '<tr>'
lista += '<td>8:30</td>'
lista += '<td> </td>'
lista += '<tr>'
lista += '<td>9:00</td>'
lista += '<td> </td>'
lista += '<tr>'
lista += '<td>9:30</td>'
lista += '<td> </td>'
lista += '<tr>'
lista += '<td>10:00</td>'
lista += '<td> </td>'
lista += '<tr>'
lista += '<td>8:00</td>'
lista += '<td> </td>'
lista += '<tr>'
lista += '<td>10:30</td>'
lista += '<td> </td>'
lista += '<tr>'
lista += '<td>11:00</td>'
lista += '<td> </td>'
lista += '<tr>'
lista += '<td>11:30</td>'
lista += '<td> </td>'
lista += '<tr>'
lista += '<td>12:00</td>'
lista += '<td> </td>'
lista += '<tr>'
lista += '<td>12:30</td>'
lista += '<td> </td>'
lista += '<tr>'
lista += '<td>13:00</td>'
lista += '<td> </td>'
lista += '<tr>'
lista += '<td>13:30</td>'
lista += '<td> </td>'
lista += '<tr>'
lista += '<td>14:00</td>'
lista += '<td> </td>'
lista += '<tr>'
lista += '<td>14:30</td>'
lista += '<td> </td>'
lista += '<tr>'
lista += '<td>15:00</td>'
lista += '<td> </td>'
lista += '<tr>'
lista += '<td>15:30</td>'
lista += '<td> </td>'
lista += '<tr>'
lista += '<td>16:00</td>'
lista += '<td> </td>'
lista += '<tr>'
lista += '<td>16:30</td>'
lista += '<td> </td>'
lista += '<tr>'
lista += '<td>17:00</td>'
lista += '<td> </td>'
lista += '<tr>'
lista += '<td>17:30</td>'
lista += '<td> </td>'
lista += '<tr>'
lista += '<td>18:00</td>'
lista += '<td> </td>'
lista += '<tr>'
lista += '<td>18:30</td>'
lista += '<td> </td>'
lista += '<tr>'
lista += '<td>19:00</td>'
lista += '<td> </td>'
lista += '<tr>'
lista += '</table>';
$('#teste').html(lista);
});
},
error: function() {
alert("Error.");
}
});
}
});
});
</script>
ret_data.php
<?php
$date = $_POST['date'];
$conecta = mysqli_connect("localhost","root","","odonto");
$selecao = "SELECT * from agenda WHERE dataAgenda = '{$date}' ";
$categorias = mysqli_query($conecta,$selecao);
$retorno = array();
while($linha = mysqli_fetch_object($categorias)) {
$retorno[] = $linha;
}
echo json_encode($retorno);
// fechar conecta
mysqli_close($conecta); ?>
html:
<body>
<div id="datepicker"></div> <br>
<div id="teste"> </div>
</body>
return when I click on the date:
[{"agendaId":"4","dentistaId":"2","dataAgenda":"2015-12-03","horaAgenda":"09:30","descricaoAgenda":"Aparelho"},{"agendaId":"8","dentistaId":"3","dataAgenda":"2015-12-03","horaAgenda":"11:30","descricaoAgenda":"Peixe"}]
I need a light to continue I’m stuck after receiving the parseJson.. How can I check the values received check if it contains, for example, 08:30 and if yes insert the description of the id of this time in the table?
Fernando, could you show an example of the return of json ?
– Gabriel Rodrigues
Hi Highlander, I put there the question already, but anyway this is my return: [{"agendaId":"4","dentistaId":"2","dataAgenda":"2015-12-03","horaAgenda":"09:30","descricaoAgenda":"Aparelho"},{"agendaId":"8","dentistaId":"3","dataAgenda":"2015-12-03","horaAgenda":"11:30","descricaoAgenda":"Peixe"}]
– Fernando Fefu