<bdo id='RWlpI'></bdo><ul id='RWlpI'></ul>

  • <small id='RWlpI'></small><noframes id='RWlpI'>

  • <i id='RWlpI'><tr id='RWlpI'><dt id='RWlpI'><q id='RWlpI'><span id='RWlpI'><b id='RWlpI'><form id='RWlpI'><ins id='RWlpI'></ins><ul id='RWlpI'></ul><sub id='RWlpI'></sub></form><legend id='RWlpI'></legend><bdo id='RWlpI'><pre id='RWlpI'><center id='RWlpI'></center></pre></bdo></b><th id='RWlpI'></th></span></q></dt></tr></i><div id='RWlpI'><tfoot id='RWlpI'></tfoot><dl id='RWlpI'><fieldset id='RWlpI'></fieldset></dl></div>
      <tfoot id='RWlpI'></tfoot>

        <legend id='RWlpI'><style id='RWlpI'><dir id='RWlpI'><q id='RWlpI'></q></dir></style></legend>

        生成两个日期之间的日期列表并将列表保存在数据库中

        generate list of dates between 2 dates and save list in database(生成两个日期之间的日期列表并将列表保存在数据库中)
        <tfoot id='JuaHq'></tfoot>
        <i id='JuaHq'><tr id='JuaHq'><dt id='JuaHq'><q id='JuaHq'><span id='JuaHq'><b id='JuaHq'><form id='JuaHq'><ins id='JuaHq'></ins><ul id='JuaHq'></ul><sub id='JuaHq'></sub></form><legend id='JuaHq'></legend><bdo id='JuaHq'><pre id='JuaHq'><center id='JuaHq'></center></pre></bdo></b><th id='JuaHq'></th></span></q></dt></tr></i><div id='JuaHq'><tfoot id='JuaHq'></tfoot><dl id='JuaHq'><fieldset id='JuaHq'></fieldset></dl></div>

        • <bdo id='JuaHq'></bdo><ul id='JuaHq'></ul>

          <small id='JuaHq'></small><noframes id='JuaHq'>

                    <tbody id='JuaHq'></tbody>
                  <legend id='JuaHq'><style id='JuaHq'><dir id='JuaHq'><q id='JuaHq'></q></dir></style></legend>
                  本文介绍了生成两个日期之间的日期列表并将列表保存在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  对于我目前遇到的问题,我需要一些帮助.我需要使用列表中的第一个和最后一个日期生成日期列表,然后将生成的日期列表保存在数据库表中.最好的方法是什么?

                  I would like a bit of help with an issue I'm currently having. I need to generate a list of dates using the first and last date in the list and then save the list of dates generated in a database table. What is the best way to do this?

                  到目前为止我的代码:

                  <?php
                  
                      $apartment = (isset($_POST['apartment']) ? $_POST['apartment'] : null);
                      $name = (isset($_POST['name']) ? $_POST['name'] : null);
                      $surname = (isset($_POST['surname']) ? $_POST['surname'] : null);
                      $email = (isset($_POST['email']) ? $_POST['email'] : null);
                      $address = (isset($_POST['address']) ? $_POST['address'] : null);
                      $mobile = (isset($_POST['mobile']) ? $_POST['mobile'] : null);
                      $pax = (isset($_POST['pax']) ? $_POST['pax'] : null);
                      $address = (isset($_POST['address']) ? $_POST['address'] : null);
                      $remarks = (isset($_POST['remarks']) ? $_POST['remarks'] : null);
                      $day_from = (isset($_POST['day_from']) ? $_POST['day_from'] : null);
                      $month_from = (isset($_POST['month_from']) ? $_POST['month_from'] : null);
                      $year_from = (isset($_POST['year_from']) ? $_POST['year_from'] : null);
                      $booking_from = $year_from."-".$month_from."-".$day_from;
                      $day_to = (isset($_POST['day_to']) ? $_POST['day_to'] : null);
                      $month_to = (isset($_POST['month_to']) ? $_POST['month_to'] : null);
                      $year_to = (isset($_POST['year_to']) ? $_POST['year_to'] : null);
                      $booking_to = $year_to."-".$month_to."-".$day_to;
                      $no_of_nights = abs(strtotime($booking_to) - strtotime($booking_from));     
                      $days = floor($no_of_nights / (60*60*24));
                  
                     include 'connect.php';
                  
                   if (!$conn->autocommit(FALSE)) {
                      printf("Errormessage: %s
                  ", $conn->error);
                   }
                  
                   if (!$conn->query("INSERT INTO client_details (clientID, name, email, address, mobile) VALUES ('', '$name $surname', '$email', '$address', '$mobile')")) {
                       printf("Errormessage: %s
                  ", $conn->error);
                   }
                  
                   if (!$conn->query("INSERT INTO bookings (bookingID, apartmentID, clientID, date_from, date_to, nights, pax, remarks) VALUES ('', '$apartment', LAST_INSERT_ID(), '$booking_from', '$booking_to', '$days', '$pax', '$remarks')")) {
                       printf("Errormessage: %s
                  ", $conn->error);
                   }
                  
                  function dateArray($booking_from, $booking_to) {
                      echo "yo";
                  
                      $aryRange = array();
                  
                       $iDateFrom=mktime(1,0,0,substr($booking_from,5,2),     substr($booking_from,8,2),substr($booking_from,0,4));
                      $iDateTo=mktime(1,0,0,substr($booking_to,5,2),     substr($booking_to,8,2),substr($booking_to,0,4));
                  
                  if ($iDateTo>=$iDateFrom) {
                      array_push($aryRange, date('Y-m-d', $iDateFrom));
                      {
                          while ($iDateFrom<$iDateTo)
                          {
                              $iDateFrom+=86400; // add 24 hours
                          array_push($aryRange,date('Y-m-d',$iDateFrom));
                          }
                      }
                      return $aryRange;
                      }
                  
                  
                  
                  dateArray($booking_from, $booking_to);
                  
                    if (!$conn->query("INSERT INTO room_nights (bookingID, apartmentID, dates) VALUES (LAST_INSERT_ID(), '$apartment', '$dates['dates']')")) {
                       printf("Errormessage: %s
                  ", $conn->error);
                   }
                  
                  
                   if (!$conn->commit()) {
                       printf("Errormessage: %s
                  ", $conn->error);
                   }
                   $conn->close();
                  }
                  
                  ?>
                  

                  推荐答案

                  这是我对这个问题的解决方案.

                  Here is my solution to the question.

                  第 1 步:创建一个包含日期的数组
                  Step2:遍历数组,在数据库表中插入日期;

                  Step1: Create an array with the dates
                  Step2: Loop through the array and insert the dates in the database table;

                  <?php
                  $day_from = (isset($_POST['day_from']) ? $_POST['day_from'] : null);
                  $month_from = (isset($_POST['month_from']) ? $_POST['month_from'] : null);
                  $year_from = (isset($_POST['year_from']) ? $_POST['year_from'] : null);
                  $booking_from = $year_from."-".$month_from."-".$day_from;
                  $day_to = (isset($_POST['day_to']) ? $_POST['day_to'] : null);
                  $month_to = (isset($_POST['month_to']) ? $_POST['month_to'] : null);
                  $year_to = (isset($_POST['year_to']) ? $_POST['year_to'] : null);
                  $booking_to = $year_to."-".$month_to."-".$day_to;
                  $no_of_nights = abs(strtotime($booking_to) - strtotime($booking_from));     
                  $days = floor($no_of_nights / (60*60*24));
                  
                  // create array with dates 
                  function daterange($booking_from, $booking_to, $step = '+1 day', $output_format = 'Y-m-d') {
                   $dates = array();
                   $first = new DateTime($booking_from);
                   $last = new DateTime($booking_to);
                   $interval = DateInterval::createFromDateString($step);
                   $period = new DatePeriod($first, $interval, $last);
                  
                   foreach ($period as $date) {
                    $dates[] = $date->format($output_format);
                    }
                  
                     return $dates;
                   }
                  
                   $dates = daterange($booking_from, $booking_to);
                  
                    print_r($dates);
                  
                    include 'connect.php';
                  
                    if (!$conn->autocommit(FALSE)) {
                    printf("Errormessage: %s
                  ", $conn->error);
                    }
                  
                    // loop thru dates and save in database table
                    foreach ($dates as $date) {
                    if (!$conn->query("INSERT INTO room_nights (bookingID, apartmentID, dates) VALUES (LAST_INSERT_ID(), '$apartment', '$date')")) {
                    printf("Errormessage: %s
                  ", $conn->error);
                   }
                     }
                  
                   if (!$conn->commit()) {
                   printf("Errormessage: %s
                  ", $conn->error);
                  }
                  $conn->close();
                  
                   ?>
                  

                  这篇关于生成两个日期之间的日期列表并将列表保存在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                    <i id='AoXBX'><tr id='AoXBX'><dt id='AoXBX'><q id='AoXBX'><span id='AoXBX'><b id='AoXBX'><form id='AoXBX'><ins id='AoXBX'></ins><ul id='AoXBX'></ul><sub id='AoXBX'></sub></form><legend id='AoXBX'></legend><bdo id='AoXBX'><pre id='AoXBX'><center id='AoXBX'></center></pre></bdo></b><th id='AoXBX'></th></span></q></dt></tr></i><div id='AoXBX'><tfoot id='AoXBX'></tfoot><dl id='AoXBX'><fieldset id='AoXBX'></fieldset></dl></div>
                      <tbody id='AoXBX'></tbody>

                      <tfoot id='AoXBX'></tfoot>

                      <legend id='AoXBX'><style id='AoXBX'><dir id='AoXBX'><q id='AoXBX'></q></dir></style></legend>
                        <bdo id='AoXBX'></bdo><ul id='AoXBX'></ul>

                        <small id='AoXBX'></small><noframes id='AoXBX'>