首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如果使用mysqli和php在datepicker中的数据库中的日期= date,我如何在datepicker上显示表内容

如果使用mysqli和php在datepicker中的数据库中的日期= date,我如何在datepicker上显示表内容
EN

Stack Overflow用户
提问于 2018-09-29 05:27:49
回答 1查看 0关注 0票数 0

我希望在DatePicker更改时从数据库获取订单信息和日期。

请通过编写代码帮助我,因为我还是PHP新手。

码:

<form id="myform" name="myform">
    <input type = "text" name = "datepicker"  id="datepicker" />
    <input type="button" id="submitMe">

$(function() {
    $("#datepicker").datepicker({
        dateFormat: "mm-dd-yy",
    }).datepicker("setDate", new Date());
});

$q_customer = $conn->query("SELECT * from orders inner JOIN 
            customer_order on customer_order.order_no 
            =orders.order_no inner join driver_order  on 
            driver_order.order_no=orders.order_no LEFT JOIN 
            customer on customer.phone=customer_order.phone 
            order by k_time" ) or die(mysqli_error());

$k_time = '';

while($f_customer = $q_customer->fetch_array()){?>

  <tr>
    <?php

    if($k_time == '' || $k_time != $f_customer['k_time']){

      $k_time = $f_customer['k_time'];

      echo "<td>".$f_customer['k_time']."</td>";

    } else{
      echo "<td>&nbsp;</td>";
    }
    ?>

    <td><?php echo $f_customer['order_no']?></td>
    <td><?php echo $f_customer['first_name']?></td>
    <td><?php echo $f_customer['last_name']?></td>
    <td><?php echo $f_customer['address']?></td>
    <td><?php echo $f_customer['driver_no']?></td>
    <td><?php echo $f_customer['d_time']?></td>
    <td><?php echo $f_customer['no_ofppl']?></td>
EN

回答 1

Stack Overflow用户

发布于 2018-09-29 14:46:42

如果我理解正确:你想执行一些PHP代码,用数据库日期检查数据日期保存在数据库中。当datepicker输入字段发生更改时,您希望执行该PHP代码

要完成此任务,您可以使用Ajax调用。使用Ajax调用,您可以从php文件中获取结果,而无需重新加载页面。我建议使用JqueryBootstrap数据贴纸。当然你可以使用另一个datepicker插件,但是你需要查看该文档如何在日期更改时执行js函数。

使用Bootstrap数据贴纸,它将如下所示

$('#datepicker').datepicker().on('changeDate', function () {
    //js code executed when #datepicker data changes

    //get te data
    var datepickerDate = $('#datepicker').val(); //date of datepicker
    var data = {datepickerDate: datepickerDate};
    var json = JSON.stringify(data);
    var url = "check_date.php" //URL to a php file, I would call it check_date.php

    //set up ajax call
    $.ajax({
      method: "POST",
      url: url,
      data: {data: json}
    })
    .done(function( result ) {//when the ajax call was successfully executed
      //we will add things here later
    });
});

这会将datepicker inputvield的日期发送到名为的php文件 check_data.php

check_data.php 将如下所示:

<?php
if(isset($_POST['data'])) {//check if data has been send
  /* we made a json of data so we first need to decode the json. 
  We can access data with $_POST because we used the method POST in the ajax call*/
  $data = json_decode($_POST['data']);

  /* now define the variable $date to the $date you send with POST */
  $date = $data->datepickerDate;
  /* now you need the date saved in your database */
  $DBdate = "Put your database date here";

  /* now you can check if they are equal */
  if($date == $DBdate) {
    echo 'true'; //when dates are equal
  } else {
    echo 'false'; //when dates are not equal
  }
}?>

此文件现在将返回true或false,具体取决于datebasedate是否等于datepicker-date

这意味着我们现在可以编写ajax调用完成后要做的事情

.done(function( result ) {//when the ajax call was successfully executed
  //result will be the result the php file gives us (true or false)
  if(result == true) {
    //display your table
  } else {
    //do nothing or inform the user that the dates do not match
  }
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100002811

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档