Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
Almacene valores json en una matriz

Hola, no tengo mucha experiencia, pero generalmente con la ayuda de Google puedo resolverlo, pero no hoy. Estoy haciendo un programa de citas y tengo problemas para bloquear valores de una base de datos en el selector de fechas.

JS:

 <script> $( function() { $( "#datepicker" ).datepicker({ minDate: 2, maxDate: "1w", beforeShowDay: function(date) { var dates = new Array(); $.ajax({ url:"load_days.php", type:"POST", success:function(data) { for (var i = 0; i < data.length; i++){ dates.push(data) } }, dataType:"json" }) var string = jQuery.datepicker.formatDate('dd-mm-yy', date); return [ dates.indexOf(string) == -1 ] } }); } ); </script>

archivo PHP:

 $data = array(); $query = "SELECT * FROM events ORDER BY id"; $statement = $connect->prepare($query); $statement->execute(); $result = $statement->fetchAll(); foreach($result as $row) { $data[] = array( 'day' => date("dmY", strtotime($row["start_event"])) ); } echo json_encode($data);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

En primer lugar, sugeriría modificar el script PHP para eliminar el contenedor de matriz ['day' => date] alrededor de la fecha de cada evento. Eso facilitará que JavaScript encuentre fechas en la matriz.

 foreach($result as $row) { $data[] = date("dmY", strtotime($row["start_event"])); }

Luego, reorganizaría un poco el JS para que las fechas de load_days.php solo se carguen una vez y luego se reutilicen en lugar de recargarse en cada evento beforeShowDay. Después de reformatear los datos que PHP devuelve como se muestra arriba, la matriz devuelta por ajax se puede usar directamente, por lo que ya no se necesita el bucle for para transformarla.

 $( function() { $.ajax({ url: "load_days.php", type: "POST", success: function (dates) { $( "#datepicker" ).datepicker({ minDate: 2, maxDate: "1w", beforeShowDay: function(date) { var string = jQuery.datepicker.formatDate('dd-mm-yy', date); return [dates.indexOf(string) === -1] } }) }, dataType: "json" }); })
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!