Php 每次刷新页面时数量不会增加
每次刷新页面时,我试图做的是添加已输入的数量,使其成为一个总数,但它仍然停留在Php 每次刷新页面时数量不会增加,php,Php,每次刷新页面时,我试图做的是添加已输入的数量,使其成为一个总数,但它仍然停留在6上,总共有11项需要输入 代码更新: $insertedBookings = 0; foreach($json->data as $row) { if (!in_array($row->guestEmail, $emails) && date('Y-m-d', strtotime($row->startDate)) == date('Y
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"];
因为count($guests)在计算$guests数组中的元素数,该数组为6(FirstName、LastName等)。因为count($guests)在计算$guests数组中的元素数,该数组为6(FirstName、LastName等)。谢谢,我怎样才能使它计算出有多少个对象?计算它通过循环的次数$计数器=0//在foreach循环之前执行此操作。foreach(..){$counter++;}谢谢,我已经将它移到$guest数组之上,但是我仍然得到6:)$json->data包含什么?你把它打印出来看它有你要找的数据吗?这可能就是现在的问题所在。啊,谢谢,我怎样才能让它计算出有多少个对象?计算它通过循环的次数$计数器=0//在foreach循环之前执行此操作。foreach(..){$counter++;}谢谢,我已经将它移到$guest数组之上,但是我仍然得到6:)$json->data包含什么?你把它打印出来看它有你要找的数据吗?这可能就是问题所在。