Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $user = "root";
- $pass = "";
- $host = "localhost";
- $dbname = "neardeal";
- $store_id = $_REQUEST['store_id'];
- // Create connection
- $conn = new mysqli($host, $user, $pass, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- //get data
- $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)
- where p.store_id = {$store_id}";
- //$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 ";
- //memasukkan hasil sql menjadi array
- $result = $conn->query($sql);
- $deals = array();
- //membuat array menjadi baris
- while($row = $result->fetch_assoc()) {
- $deal = array(
- 'id' => $row['id'],
- 'start_date' => $row['start_date'],
- 'end_date' => $row['end_date'],
- 'discount' => $row['discount'],
- 'selisih' => $row['selisih_hari'],
- 'product' => array(
- 'id' => $row['id'],
- 'store_id' => $row['store_id'],
- 'name' => $row['name'],
- 'price' => $row['price'],
- 'description' => $row['description'],
- 'photo' => $row['photo'],
- )
- );
- $deals[] = $deal;
- }
- //membuat hasil array menjadi output json
- echo json_encode(array(
- 'success' => true,
- 'deal' => $deals
- ));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement