2017-07-01 4 views
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"]; 

答えて

0

数($のゲストは)6(などのFirstName、LastNameの、)で$客の配列の要素数をカウントしているため。

+0

ahhありがとう、どうすればオブジェクト数を数えることができますか? –

+0

ループを通過する回数をカウントします。 $カウンタ= 0; // foreachループの前でこれを行います。 foreach(....){ $ counter ++; } – Difster

+0

ありがとう、私は$ゲスト配列の上に移動しましたが、私はまだ6を得ています:) –

関連する問題