Advertisement
Guest User

Untitled

a guest
Jul 11th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. <?php
  2. $servername = "nitroxtech.c48qi7cc3kyh.us-west-1.rds.amazonaws.com";
  3. $username = "NitroxAdmin";
  4. $password = "5tgjkl123";
  5.  
  6. // Create connection
  7. $conn = new mysqli($servername, $username, $password, "StorageDBWebAppMainDatabase");
  8.  
  9. // Check connection
  10. if ($conn->connect_error) {
  11. die("Connection failed: " . $conn->connect_error);
  12. }
  13.  
  14. $sql = "SELECT dateCreated FROM FacilitiesUnitsHistory WHERE facilityId=" . htmlspecialchars($_GET["facilityId"]) . " AND unitId=" . htmlspecialchars($_GET["unitId"]) . " ORDER BY dateCreated ASC";
  15. $facilityToUnits = $conn->query($sql);
  16. $dateCreatedArray = array();
  17. $rateAmountArray = array();
  18. $rowArray = array();
  19. if ($facilityToUnits->num_rows > 0) {
  20. // output data of each row
  21. while($row = $facilityToUnits->fetch_assoc()) {
  22. array_push($rateAmountArray, $row['rateAmount']);
  23. array_push($dateCreatedArray, $row['dateCreated']);
  24. }
  25. } else {
  26. echo "0 results";
  27. }
  28.  
  29. $sql = "SELECT dateCreated FROM FacilitiesUnits WHERE facilityId=" . htmlspecialchars($_GET["facilityId"]) . " AND unitId=" . htmlspecialchars($_GET["unitId"]);
  30. $facilityToUnits = $conn->query($sql);
  31. if ($facilityToUnits->num_rows > 0) {
  32. // output data of each row
  33. while($row = $facilityToUnits->fetch_assoc()) {
  34. array_push($rateAmountArray, $row['rateAmount']);
  35. array_push($dateCreatedArray, $row['dateCreated']);
  36. }
  37. } else {
  38. echo "0 results";
  39. }
  40.  
  41. for ($x = 0; $x < count($dateCreatedArray); $x++) {
  42. $rowArray[$x]['dateCreated'] = $dateCreatedArray[$x];
  43. $rowArray[$x]['rateAmount'] = $rateAmountArray[$x];
  44. }
  45.  
  46. echo json_encode($rowArray);
  47.  
  48. $conn->close();
  49. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement