0

I am creating an Android Application that requires information to be retrieved from a MySQL database on a MAMP server. I have written PHP code to try retrieve the information from the database however there is no information being retrieved from the database. I have checked the code using PHP code checker and there is no issues found. Can anyone find any issues or provide any links to help. Thank you in advance.

<?php

/*
 * Following code will list all the products
 */

// array for JSON response
$response = array();

// include db connect class
 require_once('connect.php');

// connecting to db
//$db = new db_name();

// get all products from products table
$result = mysqli_query("SELECT * FROM tbl_book");

// check for empty result
if (mysqli_num_rows($result) > 0) {
    // looping through all results
    // book node
    $response["books"] = array();

    while ($row = mysqli_fetch_array($result)) {
        // temp user array
        $book = array();
        $book["id"] = $row["id"];
        $book["title"] = $row["title"];
        $book["description"] = $row["description"];
        $book["bookID"] = $row["bookID"];

        // push single book into final response array
        array_push($response["books"], $book);
    }
    // success
    $response["success"] = 1;

    // echoing JSON response
    echo json_encode($response);
} else {
    // no products found
    $response["success"] = 0;
    $response["message"] = "No book found";

    // echo no users JSON
    echo json_encode($response);
}
?>
Elye
  • 53,639
  • 54
  • 212
  • 474
PeterJenkin
  • 7
  • 1
  • 5
  • Procedural approach to `mysqli` requires two arguments for `mysqli_query`. Refer to manuals please - http://php.net/manual/en/mysqli.query.php#refsect1-mysqli.query-examples – u_mulder May 22 '16 at 13:38
  • `array_push($response["books"], $book);` but the array you've created is called `$course`. – Jonnix May 22 '16 at 13:38
  • Possible duplicate of [Can I mix MySQL APIs in PHP?](http://stackoverflow.com/questions/17498216/can-i-mix-mysql-apis-in-php) – u_mulder May 22 '16 at 13:39
  • And start with making sure you know the difference between `mysql` and `mysqli` – u_mulder May 22 '16 at 13:40
  • When you say no result, is it passing the `if (mysqli_num_rows($result) > 0)` statement? – Elye May 22 '16 at 13:58

0 Answers0