PHP,如果还有其他逻辑

时间:2019-02-01 13:40:49

标签: php if-statement

我在这里只是遇到if / else或一些逻辑问题的问题,我有一个全日历显示所有保留日期,我将每个日期的保留限制为5,但是当我保留2个或更多时日期,并保留其他日期,它给我的结果与4相同。

global $db;
$data = array();

$query = "SELECT * FROM reserve_master
          INNER JOIN reserve_details
          on reserve_master.reserve_id = reserve_details.reserve_id
          INNER JOIN reserve_indicator
          on reserve_master.reserve_id = reserve_indicator.reserve_id
          WHERE reserve_indicator.touserid = '$id'
          AND reserve_master.type = 'Repair' ";

$res = mysqli_query($db,$query);
$count = mysqli_num_rows($res);
$count = 5 - $count;//count the available slot
$date_changed = "";
$reserve_id = 0;

foreach ($res as $row) 
{
date_default_timezone_set('Asia/Manila');

    $current_timestamp = strtotime($row["dateend"] . '+1 day');

    $time = date("Y/m/d",$current_timestamp);


    if($row["datestart"] == $date_changed)
    {
      //This is for avoiding repeating graph on fullcalendar
    }
    else
    {
        if(empty($count))
        {
            $count = '0';
        }
        else
        {
            $count;
        }

        $data[] = array(
            'id'    => $row["reserve_id"],
            'title' => $count,
            'start' => $row["datestart"],
            'end' => $time,
            'color' =>getColor($row["status"])
                );
        $date_changed = $row["datestart"];
        $reserve_id = $row["reserve_id"];
    }

}

        echo json_encode($data);

This is image of the error with captions

数据库

CREATE TABLE `reserve_master` (
`reserve_id` int(11) NOT NULL AUTO_INCREMENT,
`datestart` date NOT NULL,
`dateend` date NOT NULL,
`type` varchar(255) NOT NULL,
PRIMARY KEY (`reserve_id`)
) ENGINE=InnoDB AUTO_INCREMENT=47 DEFAULT CHARSET=latin

CREATE TABLE `reserve_indicator` (
    `indicator_id` int(11) NOT NULL AUTO_INCREMENT,
    `reserve_id` int(11) NOT NULL,
    `touserid` int(11) NOT NULL,
    `byuserid` int(11) NOT NULL,
    PRIMARY KEY (`indicator_id`),
    KEY `reserve_id` (`reserve_id`) USING BTREE,
    CONSTRAINT `reserve_indicator_ibfk_1` FOREIGN KEY (`reserve_id`) REFERENCES `reserve_master` (`reserve_id`)
) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=latin1


CREATE TABLE `reserve_details` (
 `details_id` int(11) NOT NULL AUTO_INCREMENT,
 `reserve_id` int(11) NOT NULL,
 `title` varchar(255) NOT NULL,
 `description` varchar(255) NOT NULL,
 `status` varchar(255) NOT NULL,
 `location` varchar(255) NOT NULL,
 PRIMARY KEY (`details_id`),
 KEY `reserve_id` (`reserve_id`) USING BTREE,
 CONSTRAINT `reserve_details_ibfk_1` FOREIGN KEY (`reserve_id`) REFERENCES `reserve_master` (`reserve_id`)
) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=latin1

我所尝试的只是在2018年2月2日获得可用的版本,而不是其他版本。

1 个答案:

答案 0 :(得分:0)

代码很乱,很抱歉;

问题已经解决;

我在fullcalendar上使用eventLimit并将其设置为1

Count = 5,不减去num_rows

很少在if语句上设置

很少回答我使用行和res,因为它易于指示结果和行,并且与其他查询一样使用。

谢谢。