0

Hey I am trying to move wanted data fron json. So the data inside the json are booking data from a hotel, I got it from query to database. Basically, there are multiple data with same date on it. I just want to move data that I want to php array using simple else if statement but I can't make it works.

Here is the rule: 1. So 'booked' is more important than 'available'. Even if it is still 'available', if someone 'booked' it. For example April 10th is 'booked' the only data I want is 'April 10th booked' I don't care if it is still available. This rule also applies to 'full'. 'Booked' is more important than 'full'.

  1. Last rule: 'Booked' is equvalent with 'Missed' and 'Attended'

Here is the json:

array(128) {
  [0]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-03 08:00"
    ["end"]=>
    string(16) "2016-10-03 08:30"
    ["id_course"]=>
    string(5) "55508"
    ["image"]=>
    string(92) "http://squline.dev/dashboard/media/images/teacher/2dd22e63084c868044b8d8840ad02e35_thumb.jpg"
    ["className"]=>
    string(23) "custom-cursor bg-booked"
    ["title"]=>
    string(8) "Attended"
  }
  [1]=>
  array(5) {
    ["start"]=>
    string(16) "2016-10-03 08:00"
    ["end"]=>
    string(16) "2016-10-03 08:30"
    ["id_course"]=>
    string(5) "55508"
    ["className"]=>
    string(21) "custom-cursor bg-full"
    ["title"]=>
    string(4) "Full"
  }
  [2]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-03 08:30"
    ["end"]=>
    string(16) "2016-10-03 09:00"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(23) "custom-cursor bg-booked"
    ["title"]=>
    string(8) "Attended"
    ["image"]=>
    string(92) "http://squline.dev/dashboard/media/images/teacher/2dd22e63084c868044b8d8840ad02e35_thumb.jpg"
  }
  [3]=>
  array(5) {
    ["start"]=>
    string(16) "2016-10-03 08:30"
    ["end"]=>
    string(16) "2016-10-03 09:00"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-full"
    ["title"]=>
    string(4) "Full"
  }
  [4]=>
  array(5) {
    ["start"]=>
    string(16) "2016-10-03 09:00"
    ["end"]=>
    string(16) "2016-10-03 09:30"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-full"
    ["title"]=>
    string(4) "Full"
  }
  [5]=>
  array(5) {
    ["start"]=>
    string(16) "2016-10-03 09:30"
    ["end"]=>
    string(16) "2016-10-03 10:00"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-full"
    ["title"]=>
    string(4) "Full"
  }
  [6]=>
  array(5) {
    ["start"]=>
    string(16) "2016-10-03 10:30"
    ["end"]=>
    string(16) "2016-10-03 11:00"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-full"
    ["title"]=>
    string(4) "Full"
  }
  [7]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-03 17:00"
    ["end"]=>
    string(16) "2016-10-03 17:30"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [8]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-03 17:30"
    ["end"]=>
    string(16) "2016-10-03 18:00"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [9]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-03 18:00"
    ["end"]=>
    string(16) "2016-10-03 18:30"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [10]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-03 18:30"
    ["end"]=>
    string(16) "2016-10-03 19:00"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [11]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-03 19:00"
    ["end"]=>
    string(16) "2016-10-03 19:30"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [12]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-03 19:30"
    ["end"]=>
    string(16) "2016-10-03 20:00"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [13]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-03 20:00"
    ["end"]=>
    string(16) "2016-10-03 20:30"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [14]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-03 20:30"
    ["end"]=>
    string(16) "2016-10-03 21:00"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-full"
    ["title"]=>
    string(4) "Full"
    ["status"]=>
    bool(false)
  }
  [15]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-03 21:00"
    ["end"]=>
    string(16) "2016-10-03 21:30"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [16]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-04 08:00"
    ["end"]=>
    string(16) "2016-10-04 08:30"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-full"
    ["title"]=>
    string(4) "Full"
    ["status"]=>
    bool(false)
  }
  [17]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-04 08:30"
    ["end"]=>
    string(16) "2016-10-04 09:00"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [18]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-04 09:00"
    ["end"]=>
    string(16) "2016-10-04 09:30"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [19]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-04 09:30"
    ["end"]=>
    string(16) "2016-10-04 10:00"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [20]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-04 10:00"
    ["end"]=>
    string(16) "2016-10-04 10:30"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-full"
    ["title"]=>
    string(4) "Full"
    ["status"]=>
    bool(false)
  }
  [21]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-04 10:30"
    ["end"]=>
    string(16) "2016-10-04 11:00"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [22]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-04 13:00"
    ["end"]=>
    string(16) "2016-10-04 13:30"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [23]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-04 13:30"
    ["end"]=>
    string(16) "2016-10-04 14:00"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [24]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-04 14:00"
    ["end"]=>
    string(16) "2016-10-04 14:30"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [25]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-04 14:30"
    ["end"]=>
    string(16) "2016-10-04 15:00"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-full"
    ["title"]=>
    string(4) "Full"
    ["status"]=>
    bool(false)
  }
  [26]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-04 15:00"
    ["end"]=>
    string(16) "2016-10-04 15:30"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-full"
    ["title"]=>
    string(4) "Full"
    ["status"]=>
    bool(false)
  }
  [27]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-04 16:00"
    ["end"]=>
    string(16) "2016-10-04 16:30"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [28]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-04 16:30"
    ["end"]=>
    string(16) "2016-10-04 17:00"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [29]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-04 17:00"
    ["end"]=>
    string(16) "2016-10-04 17:30"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [30]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-04 17:30"
    ["end"]=>
    string(16) "2016-10-04 18:00"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [31]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-04 18:00"
    ["end"]=>
    string(16) "2016-10-04 18:30"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [32]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-04 18:30"
    ["end"]=>
    string(16) "2016-10-04 19:00"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [33]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-04 19:00"
    ["end"]=>
    string(16) "2016-10-04 19:30"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [34]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-04 19:30"
    ["end"]=>
    string(16) "2016-10-04 20:00"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-full"
    ["title"]=>
    string(4) "Full"
    ["status"]=>
    bool(false)
  }
  [35]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-04 20:00"
    ["end"]=>
    string(16) "2016-10-04 20:30"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-full"
    ["title"]=>
    string(4) "Full"
    ["status"]=>
    bool(false)
  }
  [36]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-04 20:30"
    ["end"]=>
    string(16) "2016-10-04 21:00"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-full"
    ["title"]=>
    string(4) "Full"
    ["status"]=>
    bool(false)
  }
  [37]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-04 21:00"
    ["end"]=>
    string(16) "2016-10-04 21:30"
    ["id_course"]=>
    string(5) "55520"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [38]=>
  array(7) {
    ["start"]=>
    string(16) "2016-10-05 08:00"
    ["end"]=>
    string(16) "2016-10-05 08:30"
    ["id_course"]=>
    string(5) "55510"
    ["className"]=>
    string(23) "custom-cursor bg-booked"
    ["title"]=>
    string(6) "Missed"
    ["status"]=>
    bool(false)
    ["image"]=>
    string(92) "http://squline.dev/dashboard/media/images/teacher/2dd22e63084c868044b8d8840ad02e35_thumb.jpg"
  }
  [39]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-05 08:00"
    ["end"]=>
    string(16) "2016-10-05 08:30"
    ["id_course"]=>
    string(5) "55510"
    ["className"]=>
    string(21) "custom-cursor bg-full"
    ["title"]=>
    string(4) "Full"
    ["status"]=>
    bool(false)
  }
  [40]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-05 08:30"
    ["end"]=>
    string(16) "2016-10-05 09:00"
    ["id_course"]=>
    string(5) "55510"
    ["className"]=>
    string(21) "custom-cursor bg-full"
    ["title"]=>
    string(4) "Full"
    ["status"]=>
    bool(false)
  }
  [41]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-05 09:00"
    ["end"]=>
    string(16) "2016-10-05 09:30"
    ["id_course"]=>
    string(5) "55510"
    ["className"]=>
    string(21) "custom-cursor bg-full"
    ["title"]=>
    string(4) "Full"
    ["status"]=>
    bool(false)
  }
  [42]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-05 09:30"
    ["end"]=>
    string(16) "2016-10-05 10:00"
    ["id_course"]=>
    string(5) "55510"
    ["className"]=>
    string(21) "custom-cursor bg-full"
    ["title"]=>
    string(4) "Full"
    ["status"]=>
    bool(false)
  }
  [43]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-05 10:30"
    ["end"]=>
    string(16) "2016-10-05 11:00"
    ["id_course"]=>
    string(5) "55510"
    ["className"]=>
    string(21) "custom-cursor bg-full"
    ["title"]=>
    string(4) "Full"
    ["status"]=>
    bool(false)
  }
  [44]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-05 13:00"
    ["end"]=>
    string(16) "2016-10-05 13:30"
    ["id_course"]=>
    string(5) "55510"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [45]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-05 13:30"
    ["end"]=>
    string(16) "2016-10-05 14:00"
    ["id_course"]=>
    string(5) "55510"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [46]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-05 14:00"
    ["end"]=>
    string(16) "2016-10-05 14:30"
    ["id_course"]=>
    string(5) "55510"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [47]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-05 14:30"
    ["end"]=>
    string(16) "2016-10-05 15:00"
    ["id_course"]=>
    string(5) "55510"
    ["className"]=>
    string(21) "custom-cursor bg-full"
    ["title"]=>
    string(4) "Full"
    ["status"]=>
    bool(false)
  }
  [48]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-05 15:00"
    ["end"]=>
    string(16) "2016-10-05 15:30"
    ["id_course"]=>
    string(5) "55510"
    ["className"]=>
    string(21) "custom-cursor bg-full"
    ["title"]=>
    string(4) "Full"
    ["status"]=>
    bool(false)
  }
  [49]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-05 15:30"
    ["end"]=>
    string(16) "2016-10-05 16:00"
    ["id_course"]=>
    string(5) "55510"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }
  [50]=>
  array(6) {
    ["start"]=>
    string(16) "2016-10-05 16:00"
    ["end"]=>
    string(16) "2016-10-05 16:30"
    ["id_course"]=>
    string(5) "55510"
    ["className"]=>
    string(21) "custom-cursor bg-past"
    ["title"]=>
    string(9) "Available"
    ["status"]=>
    bool(false)
  }

My attempt to move data that I want to php array:

foreach( $class as $key => $val )
          { 
   if ($xcourse_date != $course_date) {
                    $events[] = $event;
                    $count_x_course_date++;
                }


                  if( $events[$count_x_course_date - 1]['status'] != 'BOOKED' ) {
                    if ( $events[$count_x_course_date - 1]['status'] != 'AVAILABLE' ) {
                        $events[$count_x_course_date - 1] = $event;
                    }
                }
                 elseif ( $events[$count_x_course_date - 1]['status'] == 'AVAILABLE' ) {
                    $events[$count_x_course_date - 1] = $event;
                } 
                $xcourse_date = $val['course_date'];
                $i++;
}

My question are: 1. What did I do wrong? 2. I use loop to access all the data inside the json, is there any way easier than looping? 3. My logic says I do no wrong in my code, but the result is far from my expectation, can you point out what's wrong with my programming logic?

2
  • Did you json_decode() the json data first? Commented Oct 10, 2016 at 4:32
  • Yes I decode the json data Commented Oct 10, 2016 at 7:13

1 Answer 1

1

In your data set from database,

  1. Some of the records doesn't have status field i.e. records 0-6
  2. In your condition your're checking $events[$count_x_course_date - 1]['status'] == 'AVAILABLE' which is wrong. Because from the data set, it's saying value is boolean i.e. true/false ["status"] => bool(false).
  3. Actual values which you're checking is in title field i.e. ["title"]=> string(9) "Available"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.