armadiazrino

Untitled

Nov 17th, 2018
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. <?php
  2. $user="root";
  3. $pass="";
  4. $host="localhost";
  5. $dbname="neardeal";
  6.  
  7. $product_id = $_REQUEST['product_id'];
  8. //create connection
  9. $conn = new mysqli($host, $user, $pass, $dbname);
  10. //check connection
  11. if($conn->connect_error){
  12. die("connection failed" .$com->connect_error);
  13. }
  14.  
  15. $sql = "SELECT p.*,s.name store_name, s.photo store_photo, d.*
  16. FROM store s INNER JOIN product p ON(s.id=p.store_id) LEFT JOIN deal d ON (p.id =d.product_id)
  17. WHERE p.id={$product_id} ";
  18.  
  19. $result = $conn->query($sql);
  20. $deals = array();
  21.  
  22. while($row =$result->fetch_assoc()){
  23. $deal = array(
  24. 'id' => $row['id'],
  25. 'name' => $row ['name'],
  26. 'photo' => $row ['photo'],
  27. 'store_name' => $row['store_name'],
  28. 'store_photo' => $row['store_photo'],
  29. 'price' => $row ['price'],
  30. 'price_old' => $row['price'],
  31. 'description' => $row ['description'],
  32. );
  33. }
  34.  
  35. echo json_encode($deal);
Advertisement
Add Comment
Please, Sign In to add comment