Advertisement
Guest User

Untitled

a guest
May 25th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. <?php
  2. $user = "root";
  3. $pass = "";
  4. $host = "localhost";
  5. $dbname = "neardeal";
  6.  
  7.  
  8. $store_id = $_REQUEST['store_id'];
  9.  
  10. // Create connection
  11. $conn = new mysqli($host, $user, $pass, $dbname);
  12.  
  13. // Check connection
  14. if ($conn->connect_error) {
  15. die("Connection failed: " . $conn->connect_error);
  16. }
  17.  
  18. //get data
  19. $sql = "SELECT a.*, p.*, current_date() as tglsekarang, datediff(a.end_date, current_date()) as selisih_hari from deal as a INNER JOIN product as p ON(p.id=a.product_id)
  20. where p.store_id = {$store_id}";
  21.  
  22. //$sql = "select a.*, b.*, current_date() as tglsekarang, datediff(a.end_date, current_date()) as selisih_hari, round((b.price*a.discount/100),0) as disc, round((b.price -(b.price*a.discount/100)),0) as price_disc from deal as a inner join //product as b on a.product_id=b.id where b.store_id={$store_id} and current_date() between a.start_date and a.end_date ";
  23.  
  24. //memasukkan hasil sql menjadi array
  25. $result = $conn->query($sql);
  26. $deals = array();
  27.  
  28. //membuat array menjadi baris
  29. while($row = $result->fetch_assoc()) {
  30. $deal = array(
  31. 'id' => $row['id'],
  32. 'start_date' => $row['start_date'],
  33. 'end_date' => $row['end_date'],
  34. 'discount' => $row['discount'],
  35. 'selisih' => $row['selisih_hari'],
  36. 'product' => array(
  37. 'id' => $row['id'],
  38. 'store_id' => $row['store_id'],
  39. 'name' => $row['name'],
  40. 'price' => $row['price'],
  41. 'description' => $row['description'],
  42. 'photo' => $row['photo'],
  43. )
  44. );
  45.  
  46. $deals[] = $deal;
  47. }
  48.  
  49. //membuat hasil array menjadi output json
  50. echo json_encode(array(
  51. 'success' => true,
  52. 'deal' => $deals
  53.  
  54. ));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement