Advertisement
Guest User

Untitled

a guest
Oct 9th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.11 KB | None | 0 0
  1. <?php
  2. $user = "root";
  3. $pass = "";
  4. $host = "localhost";
  5. $dbname = "near_deal";
  6.  
  7. $store_id = $_REQUEST['store_id'];
  8.  
  9. // Create connection
  10. $conn = new mysqli($host, $user, $pass, $dbname);
  11.  
  12. // Check connection
  13. if ($conn->connect_error) {
  14.     die("Connection failed: " . $conn->connect_error);
  15. }
  16.  
  17. //get data
  18. $sql = "SELECT *,DATEDIFF(end_date,CURDATE()) sisahari FROM product as p INNER JOIN deal as d ON(p.id=d.product_id)
  19. where p.store_id = {$store_id}";
  20. //
  21. $result = $conn->query($sql);
  22. $deals = array();
  23.  
  24. while($row = $result->fetch_assoc()) {
  25.     $deal = array(
  26.         'id' => $row['id'],
  27.         'start_date' => $row['start_date'],
  28.         'end_date' => $row['end_date'],
  29.         'sisahari_discount' => $row['sisahari'],
  30.         'discount' => $row['discount'],
  31.         'product' => array(
  32.             'id' => $row['id'],
  33.             'store_id' => $row['store_id'],
  34.             'name' => $row['name'],
  35.             'price' => $row['price'],
  36.             'description' => $row['description'],
  37.             'photo' => $row['photo'],
  38.         )
  39.     );
  40.  
  41.     $deals[] = $deal;
  42. }
  43.  
  44. echo json_encode(array(
  45.     'success' => true,
  46.     'deal' => $deals
  47. ));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement