I have my php which is below with my html code. Im trying to populate a listview with php code but failing, any ideas

```
<?
require_once("../backend/functions.php");
dbconn();

$id = $CURUSER["id"]; 
$e  = date("Y/m/d");              
$a  = SQL_Query_exec("SELECT enddate FROM cal_events WHERE userid = '$id' 
                       AND enddate > '$e' ORDER BY enddate ASC");

if (mysql_num_rows($a) == 0) {
?>
  <script>
    alert("You have no active events to deal with");
   window.location ='index.html'; 
  </script>

<?
}else{

  $data = array();
  while($rowa = mysql_fetch_array($a))
  { 
    $data[] = $rowa;
  }
  echo json_encode($data);
}

```

Now my html is not correct and this is where i need a little help in the right direction

html

```
<script type="text/javascript">
  $(document).on("pagebeforeshow", "#index4", function() {
    $(function(){
      var items="";
      $.getJSON("check-events.php",function(data){
        $.each(data,function(index,item) 
        {
          items+="<li>"+item.enddate+"</li>";
        });
        $("#contacts").html(items); 
        $("#contacts").trigger("change");
      });
    });
  });  
</script>
<ul id="contacts" data-role="listview" data-divider-theme="b" data-inset="true">
</ul>

```

Where am I going wrong? It does populate the list but with no jquery elements