Guest User

Untitled

a guest
Nov 30th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <?php
  6. $servername = "localhost";
  7. $username = "user_name";
  8. $password = "password";
  9. $dbname = "db_name";
  10.  
  11. // Create connection
  12. $conn = new mysqli($servername, $username, $password, $dbname);
  13. // Check connection
  14. if ($conn->connect_error) {
  15. die("Connection failed: " . $conn->connect_error);
  16. }
  17.  
  18. $sql = "SELECT SUM((IFNULL(main_table.base_total_invoiced, 0) - IFNULL(main_table.base_tax_invoiced, 0) - IFNULL(main_table.base_shipping_invoiced, 0) - (IFNULL(main_table.base_total_refunded, 0) - IFNULL(main_table.base_tax_refunded, 0) - IFNULL(main_table.base_shipping_refunded, 0))) * main_table.base_to_global_rate) AS `lifetime`, AVG((IFNULL(main_table.base_total_invoiced, 0) - IFNULL(main_table.base_tax_invoiced, 0) - IFNULL(main_table.base_shipping_invoiced, 0) - (IFNULL(main_table.base_total_refunded, 0) - IFNULL(main_table.base_tax_refunded, 0) - IFNULL(main_table.base_shipping_refunded, 0))) * main_table.base_to_global_rate) AS `average` FROM `sales_order` AS `main_table` WHERE ( main_table.status NOT IN ( 'canceled' ) ) AND ( main_table.state NOT IN ( 'new', 'pending_payment' ) ) limit 0,1";
  19. ?>
  20. <div class="box-body table-responsive no-padding">
  21. <table class="table table-hover">
  22. <tr>
  23. <th> total sale</th>
  24. <th>
  25. average sale</th>
  26.  
  27. </tr>
  28. <tr>
  29. <?php
  30. $result = $conn->query($sql);
  31.  
  32. if ($result->num_rows > 0) {
  33. // output data of each row
  34. while($row = $result->fetch_assoc()) {
  35. ?>
  36. <td><?php echo $row['lifetime'];?></td>
  37. <td><?php echo $row['average'];?></td>
  38. <?php
  39. }
  40. } else {
  41. echo "0 results";
  42. }
  43.  
  44. $conn->close();
  45. ?>
  46. </tr>
  47. </table>
  48. </div>
  49.  
  50. </body>
  51. </html>
Add Comment
Please, Sign In to add comment