Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 尝试组合两个组件时,推荐脚本不起作用_Php_Mysql - Fatal编程技术网

Php 尝试组合两个组件时,推荐脚本不起作用

Php 尝试组合两个组件时,推荐脚本不起作用,php,mysql,Php,Mysql,上下文 我正在构建一个简单的推荐脚本,为用户提供一周中预订最多的某一天的下一个即将到来的日期。 (也就是说,约翰多最受欢迎的预订日是星期四,下一个星期四的日期是2019/03/07) 这就是我正在处理的问题: <?php $date = new DateTime(); $date->modify('next thursday'); echo $date->format('Y-m-d'); ?> <?php require "sn

上下文 我正在构建一个简单的推荐脚本,为用户提供一周中预订最多的某一天的下一个即将到来的日期。 (也就是说,约翰多最受欢迎的预订日是星期四,下一个星期四的日期是2019/03/07)

这就是我正在处理的问题:

<?php
      $date = new DateTime();
      $date->modify('next thursday');
      echo $date->format('Y-m-d');
?>

<?php require "snippets/get_booking_recommended_day.php" ?>

第一个PHP代码返回下一个即将到来的日期。这是它应该做的。PHP需要引用另一个文件夹中的代码,该文件夹以字符串格式返回用户最受欢迎的一天。(如星期一、星期二)。它也起作用

我的问题出现在试图获取第一位代码以理解从第二位代码返回的内容时

我尝试了以下几点

<?php
   $date = new DateTime();
   $date->modify('next' require "snippets/get_booking_recommended_day.php");
   echo $date->format('Y-m-d');
 ?>

我尝试了所有可能的变化。似乎什么都不管用。 我对PHP很陌生,我90%确信我的编码实践很糟糕,但我正在尽我最大的努力去掌握它——但到目前为止,这个简单的问题我还没有解决

请帮忙

附录 Filename:snippets/get\u booking\u recommended\u day.php

(返回当前会话中用户最近3个月内预订最多的一天)


问题已解决。

 <?php
 // If there are any values in the table, display them one at a time.
 if ($mysqli->connect_errno) {
   echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
 }

// Asks the qry: Of the last 90 days, what is the most booked day of the week for the current member in session?
// Min date is CURRENT_DATE() -100 instead of CURRENT_DATE() -30, because the MySQL function CURRENT_DATE() prints the date in an int format (YYYYMMDD) with no date formatting. Thus, to get the date a month ago, we must subtract this int by 100 so as to remove 1 from the 6th number in the series of numbers. Which is the 2nd M number.
 $sql = "SELECT  DATE_FORMAT(tbl_booking.booking_date, '%W'), COUNT(DATE_FORMAT(tbl_booking.booking_date, '%W')) AS mostpopularday
              FROM tbl_booking
              WHERE tbl_booking.member_ID=$_SESSION[member_ID]
                 AND tbl_booking.booking_date <= CURRENT_DATE()
                 AND tbl_booking.booking_date >= CURRENT_DATE() -300
              GROUP BY DATE_FORMAT(tbl_booking.booking_date, '%W')
              ORDER BY mostpopularday DESC
              LIMIT 1";
 $result = $mysqli->query($sql);

 if ($result->num_rows > 0) {
   // output data of each row
   while($row = $result->fetch_assoc()) {
      $recommended_day = $row["DATE_FORMAT(tbl_booking.booking_date, '%W')"];

      $date = new DateTime();
      $date->modify('next '.$recommended_day);
      echo $date->format('Y-m-d');

   }
 } else {

 }
 ?>

问题已解决。

 <?php
 // If there are any values in the table, display them one at a time.
 if ($mysqli->connect_errno) {
   echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
 }

// Asks the qry: Of the last 90 days, what is the most booked day of the week for the current member in session?
// Min date is CURRENT_DATE() -100 instead of CURRENT_DATE() -30, because the MySQL function CURRENT_DATE() prints the date in an int format (YYYYMMDD) with no date formatting. Thus, to get the date a month ago, we must subtract this int by 100 so as to remove 1 from the 6th number in the series of numbers. Which is the 2nd M number.
 $sql = "SELECT  DATE_FORMAT(tbl_booking.booking_date, '%W'), COUNT(DATE_FORMAT(tbl_booking.booking_date, '%W')) AS mostpopularday
              FROM tbl_booking
              WHERE tbl_booking.member_ID=$_SESSION[member_ID]
                 AND tbl_booking.booking_date <= CURRENT_DATE()
                 AND tbl_booking.booking_date >= CURRENT_DATE() -300
              GROUP BY DATE_FORMAT(tbl_booking.booking_date, '%W')
              ORDER BY mostpopularday DESC
              LIMIT 1";
 $result = $mysqli->query($sql);

 if ($result->num_rows > 0) {
   // output data of each row
   while($row = $result->fetch_assoc()) {
      $recommended_day = $row["DATE_FORMAT(tbl_booking.booking_date, '%W')"];

      $date = new DateTime();
      $date->modify('next '.$recommended_day);
      echo $date->format('Y-m-d');

   }
 } else {

 }
 ?>

为什么不先要求pagebooking.php,将其代码重写为函数,然后在日期中调用该函数?我很想为该列别名为什么不要求pagebooking.php,将其代码重写为函数,然后在日期中调用该函数?我很想为该列别名
 <?php
 // If there are any values in the table, display them one at a time.
 if ($mysqli->connect_errno) {
   echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
 }

// Asks the qry: Of the last 90 days, what is the most booked day of the week for the current member in session?
// Min date is CURRENT_DATE() -100 instead of CURRENT_DATE() -30, because the MySQL function CURRENT_DATE() prints the date in an int format (YYYYMMDD) with no date formatting. Thus, to get the date a month ago, we must subtract this int by 100 so as to remove 1 from the 6th number in the series of numbers. Which is the 2nd M number.
 $sql = "SELECT  DATE_FORMAT(tbl_booking.booking_date, '%W'), COUNT(DATE_FORMAT(tbl_booking.booking_date, '%W')) AS mostpopularday
              FROM tbl_booking
              WHERE tbl_booking.member_ID=$_SESSION[member_ID]
                 AND tbl_booking.booking_date <= CURRENT_DATE()
                 AND tbl_booking.booking_date >= CURRENT_DATE() -300
              GROUP BY DATE_FORMAT(tbl_booking.booking_date, '%W')
              ORDER BY mostpopularday DESC
              LIMIT 1";
 $result = $mysqli->query($sql);

 if ($result->num_rows > 0) {
   // output data of each row
   while($row = $result->fetch_assoc()) {
      $recommended_day = $row["DATE_FORMAT(tbl_booking.booking_date, '%W')"];

      $date = new DateTime();
      $date->modify('next '.$recommended_day);
      echo $date->format('Y-m-d');

   }
 } else {

 }
 ?>