title: get events from database and placing on calendar view (android)
body: <p>I have a calendar program in my android app. Now I need to get events stored in an online <code>Mysql</code> database and  place them on the calendar. Now I have a <code>php</code> file that create a <code>json</code> object. And this <code>JSON</code> object shows all the events coming from database</p>
  
  <p><strong>Calendar.php</strong></p>
  
  <pre><code>&lt;?php
  include 'DatabaseConfig.php';
  
  // Create connection
  //$conn = new mysqli($HostName, $HostUser, $HostPass, $DatabaseName);
      $conn = mysqli_connect("localhost", "id2553265_admin", "admin", "id2553265_mobile_app");
  if ($conn-&gt;connect_error) {
  
   die("Connection failed: " . $conn-&gt;connect_error);
  } 
  
  $sql = "SELECT * FROM calendar";
  
  $result = $conn-&gt;query($sql);
  
  if ($result-&gt;num_rows &gt;0) {
  
  
   while($row[] = $result-&gt;fetch_assoc()) {
  
   $tem = $row;
  
   $json = json_encode($tem);
  
  
   }
  
  } else {
   echo "No Results Found.";
  }
   echo $json;
  $conn-&gt;close();
  ?&gt;
  </code></pre>
  
  <p>In this code I insert <strong>1496134800000L</strong> to highlight the date of <strong>2017-05-30</strong>. And now I have the java code that highlight and color them blue with a specific date.</p>
  
  <pre><code>@Override
  
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
  
          View view = inflater.inflate(R.layout.fragment_calendar, container, false);
          //calendar setup
          compactCalendar = (CompactCalendarView) view.findViewById(R.id.comCalendarView);
          compactCalendar.setUseThreeLetterAbbreviation(true);
          calendarMonth = (TextView) view.findViewById(R.id.calMonth);
  
  
  
          Event may30 = new Event(Color.BLUE, **1496134800000L**, "test");
          compactCalendar.addEvent(may30);
  
          Event aug17 = new Event(Color.BLUE, 1502960400000L, "test");
          compactCalendar.addEvent(aug17);
  
  
          compactCalendar.setListener(new CompactCalendarView.CompactCalendarViewListener() {
              @Override
              public void onDayClick(Date dateClicked){
                  if (dateFormatDay.format(dateClicked).toString().compareTo("**2017-05-30**") == 0){
                      Toast.makeText(CalendarFragment.this.getContext(), "There is an event", Toast.LENGTH_SHORT).show();
                      Intent i = new Intent(getActivity(), ListMay07.class);
                      i.putExtra("Date", "Sample date");
                      startActivity(i);
  
                  }else  if (dateFormatDay.format(dateClicked).toString().compareTo("2017-08-17") == 0){
                      Toast.makeText(CalendarFragment.this.getContext(), "There is an event", Toast.LENGTH_SHORT).show();
                      Intent i = new Intent(getActivity(), ListAug17.class);
                      i.putExtra("Date", "Sample date");
                      startActivity(i);
  
                  }else{
                      Toast.makeText(CalendarFragment.this.getContext(), "No Event", Toast.LENGTH_SHORT).show();
  
                  }
              }
  
              @Override
              public void onMonthScroll(Date firstDayOfNewMonth) {
                  calendarMonth.setText(dateFormatMonth.format(firstDayOfNewMonth));
              }
  
  
  
          });
          // Inflate the layout for this fragment
          return view;
  
      }
  </code></pre>
  
  <p>My main problem is how to get the data from the database and insert it in my java code so that all of the events will be enter in the database not in the actual code.</p>
  
  <p><a href="https://i.stack.imgur.com/AlImc.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AlImc.jpg" alt="enter image description here"></a></p>
  
  <p>I want to do that by using the <code>JSON</code> object but I don't know how. </p>
  
  <pre><code>[{  
     "ID":"1",
     "Epoch_Time":"1496134800000L",
     "Date":"2017-05-30"   ‌​,
     "Description":"Cama‌​raderie Day"
  },
  {  
     "ID":"2",
     "Epoch_Time":"1502960400000L",
     "Date":"2017-0‌​8-17",
     "Description":‌​"Sample Date"
  }]
  </code></pre>