zihadrizkyef

get_all_products.php

Sep 3rd, 2016
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.83 KB | None | 0 0
  1. <?php
  2.  
  3.     $response = array();
  4.  
  5.     require_once __DIR__ .'/db_connect.php';
  6.  
  7.     $db = new DB_CONNECT();
  8.  
  9.     $result = mysql_query("SELECT * FROM products");
  10.  
  11.     if (mysql_num_rows($result) > 0) {
  12.         $response['product'] = array();
  13.         while($row = mysql_fetch_array($result)) {
  14.             $product = array();
  15.             $product['pid'] = $row['pid'];
  16.             $product['name'] = $row['name'];
  17.             $product['price'] = $row['price'];
  18.             $product['created_at'] = $row['created_at'];
  19.             $product['updated_at'] = $row['updated_at'];
  20.  
  21.             array_push($response['products'], $product);
  22.         }
  23.  
  24.         $response['success'] = 1;
  25.     } else {
  26.         $response['success'] = 0;
  27.         $response['message'] = "No product found";
  28.     }
  29.  
  30.     echo json_encode($response);
  31.  
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment