1
我每次刷新頁面時都會嘗試執行的操作$insertedBookings
應該添加輸入的數量,以使其成爲總數,但仍然保留在6
總共有11
項被輸入。頁數不會隨着每次刷新而增加
代碼更新:
$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"];
ahh謝謝,我該怎麼做才能統計有多少物體? –
計算通過循環的次數。 $ counter = 0; //在foreach循環之前執行此操作。 foreach(....){ $ counter ++; } – Difster
謝謝,我已經將它移到$ guest數組之上,但是我仍然得到6 :) –