Page 37 - 3-2
P. 37

// get all products from products table
            $result = mysqli_query($con,"SELECT *FROM mdp_table2") 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);
            } else {
                // no products found
                $response["success"] = 0;
                $response["message"] = "No products found";


                // echo no users JSON
                echo json_encode($response);
            }
            mysqli_close($con);
            ?>
            ----------------*owner_all_product_table4.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


                                                         - 37 -
   32   33   34   35   36   37   38   39   40   41   42