Page 33 - 3-2
P. 33

echo json_encode($response);
            }
            mysqli_close($con);
            ?>
            ----------------*owner_all_product.php*-------------
            <?php


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


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


            // include db connect class
            require_once __DIR__ . '/db_connect.php';


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


            // get all products from products table
            $result = mysqli_query($con,"SELECT *FROM mdp_table3") or die(mysqli_error());


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


                while ($row = mysqli_fetch_array($result)) {
                    // temp user array
                    $product = array();
                    $product["code"] = $row["code"];
                    $product["name"] = $row["name"];
                    $product["num"] = $row["num"];
                    $product["price"] = $row["price"];


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


                // echoing JSON response
                echo json_encode($response);


                                                         - 33 -
   28   29   30   31   32   33   34   35   36   37   38