daily pastebin goal
66%
SHARE
TWEET

Untitled

a guest Jan 28th, 2016 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.    
  3.     $servername = "localhost";
  4.     $username = "root";
  5.     $password = "password";
  6.     $dbname = "operation_paperless";
  7.    
  8.     //create connection
  9.     $conn = new mysqli($servername, $username, $password, $dbname);
  10.     //check connection
  11.     if ($conn->connect_error) {die("Connection failed: ".$conn->connect_error);}
  12.    
  13.     // This is the query
  14.     $sql = "SELECT id, date, start_time, end_time, company, instructor, crew, course, booked_status, requested_by, booked_by FROM s92_bookings ORDER BY date ASC, start_time ASC";
  15.     $query = mysqli_query($conn, $sql);
  16.     $list = array();
  17.     while($row = mysqli_fetch_array($query, MYSQLI_ASSOC) ) {
  18.         $list[] = array('id' => $row["id"]);
  19.         $list[] = array('date' => $row["date"]);
  20.         $list[] = array('start_time' => $row["start_time"]);
  21.         $list[] = array('end_time' => $row["end_time"]);
  22.         $list[] = array('company' => $row["company"]);
  23.         $list[] = array('instructor' => $row["instructor"]);
  24.         $list[] = array('crew' => $row["crew"]);
  25.         $list[] = array('course' => $row["course"]);
  26.         $list[] = array('booked_status' => $row["booked_status"]);
  27.         $list[] = array('requested_by' => $row["requested_by"]);
  28.         $list[] = array('booked_by' => $row["booked_by"]);
  29.     }
  30.     // Close your database connection
  31.     mysqli_close($conn);
  32.     // Echo the results back to Ajax
  33.     echo json_encode($list);
  34.     exit();
  35. ?>
  36.  
  37. //----------------Below is the output, I'd like it to be an array of '(no of rows)' JSON objects instead of an array of '(no of rows * fields)' JSON objects. Ta!
  38.  
  39. [{"id":"1"},{"date":"2016-01-01"},{"start_time":"00:00:00"},{"end_time":"02:00:00"},{"company":"asdasd"},{"instructor":"asd"},{"crew":"hgdfg"},{"course":"zf"},{"booked_status":"booked"},{"requested_by":"zfsd"},{"booked_by":"sdfg"},{"id":"2"},{"date":"2016-01-01"},{"start_time":"04:00:00"},{"end_time":"06:00:00"},{"company":"gimpo"},{"instructor":"gimpo"},{"crew":"gimpy"},{"course":"gimp"},{"booked_status":"booked"},{"requested_by":"mr gimp"},{"booked_by":"mrs gimp"}]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top