Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "password";
- $dbname = "operation_paperless";
- //create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- //check connection
- if ($conn->connect_error) {die("Connection failed: ".$conn->connect_error);}
- // This is the query
- $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";
- $query = mysqli_query($conn, $sql);
- $list = array();
- while($row = mysqli_fetch_array($query, MYSQLI_ASSOC) ) {
- $list[] = array('id' => $row["id"]);
- $list[] = array('date' => $row["date"]);
- $list[] = array('start_time' => $row["start_time"]);
- $list[] = array('end_time' => $row["end_time"]);
- $list[] = array('company' => $row["company"]);
- $list[] = array('instructor' => $row["instructor"]);
- $list[] = array('crew' => $row["crew"]);
- $list[] = array('course' => $row["course"]);
- $list[] = array('booked_status' => $row["booked_status"]);
- $list[] = array('requested_by' => $row["requested_by"]);
- $list[] = array('booked_by' => $row["booked_by"]);
- }
- // Close your database connection
- mysqli_close($conn);
- // Echo the results back to Ajax
- echo json_encode($list);
- exit();
- ?>
- //----------------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!
- [{"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"}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement