Advertisement
colmulhall

Untitled

Apr 1st, 2014
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.74 KB | None | 0 0
  1. <?php
  2.     $username = 'root';
  3.     $password = '';
  4.     $database = 'test';
  5.     $host = 'localhost';
  6.  
  7.     // create connection to the database
  8.         $con = mysqli_connect($host, $username, $password, $database);
  9.  
  10.     // select database
  11.     mysqli_select_db($con, $database)or die("cannot select DB");
  12.  
  13.     // return all event titles from the database ordered by date
  14.     $sql = "select id, title, location, date from event_list order by id desc";
  15.  
  16.         $result = mysqli_query($con, $sql);
  17.     $json = array();
  18.  
  19.     // get each row of data from the database
  20.     if(mysqli_num_rows($result))
  21.     {
  22.             while($row = mysqli_fetch_assoc($result))
  23.             {
  24.                 $json['event_list'][] = $row;
  25.             }
  26.             echo json_encode($json);
  27.     }
  28.     mysqli_close($con);
  29. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement