每次刷新页面时数量不会增加

时间:2017-07-01 03:11:56

标签: php

每次刷新页面时我想尝试做的事情$insertedBookings应该添加输入的数量,以便它变为总数但是它仍然保持在6总共11 1}}要输入的项目。

代码已更新:

    $insertedBookings = 0;
    foreach($json->data as $row)
        {
        if (!in_array($row->guestEmail, $emails) && date('Y-m-d', strtotime($row->startDate)) == date('Y-m-d'))
            {
$insertedBookings ++;

            $guests[] = array(
                'FirstName' => $row->guestFirstName,
                'LastName' => $row->guestLastName,
                'email' => $row->guestEmail,
                'country' => $row->guestCountry,
                'check-in_date' => $row->startDate,
                'check-out_date' => $row->endDate,
            );
            $emails[] = $row->guestEmail;
            }
        }

    // Insert to IF HERE

    if (!isset($_SESSION["totalInsertedBookings"]))
        {
        $_SESSION["totalInsertedBookings"] = $insertedBookings;
        }

    $currentInsertedBooking = $_SESSION["totalInsertedBookings"];

**Code:**  

    $insertedBookings = 0;
    foreach($json->data as $row)
        {
        if (!in_array($row->guestEmail, $emails) && date('Y-m-d', strtotime($row->startDate)) == date('Y-m-d'))
            {
            $guests[] = array(
                'FirstName' => $row->guestFirstName,
                'LastName' => $row->guestLastName,
                'email' => $row->guestEmail,
                'country' => $row->guestCountry,
                'check-in_date' => $row->startDate,
                'check-out_date' => $row->endDate,
            );
            $emails[] = $row->guestEmail;
            $insertedBookings = count($guests);
            }
        }

    // Insert to IF HERE

    if (!isset($_SESSION["totalInsertedBookings"]))
        {
        $_SESSION["totalInsertedBookings"] = $insertedBookings;
        }

    $currentInsertedBooking = $_SESSION["totalInsertedBookings"];

1 个答案:

答案 0 :(得分:0)

因为count($ guests)正在计算$ guests数组中6的元素数(FirstName,LastName等)。