Advertisement
Guest User

Untitled

a guest
Feb 15th, 2017
9,441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. user_id | login | email
  2. ---------- | ------------- | ------------
  3. 1 | AD1 | email1@email.com
  4. 2 | AD2 | email2@email.com
  5.  
  6. id | user_id | dtfrom | dtto
  7. ---------- | ------------- | ------------ ------------
  8. 1 | AD1 | 2017-12-12 | 2017-12-12
  9. 2 | AD1 | 2017-12-13 | 2017-12-13
  10. 3 | AD2 | 2017-12-20 | 2017-12-20
  11.  
  12. {
  13. "login":"AD1",
  14. "email":"email1@email.com",
  15. "movement":
  16. [
  17. {
  18. "dtfrom":"2017-12-12",
  19. "dtto":"2017-12-12"
  20. },
  21. {
  22.  
  23. "dtfrom":"2017-12-13",
  24. "dtto":"2017-12-13"
  25. }
  26. ]
  27. }
  28.  
  29. {
  30. "login":"AD1",
  31. "email":"email1@email.com",
  32. "0":
  33. {
  34. "dtfrom":"2017-12-12",
  35. "dtto":"2017-12-12"
  36. },
  37. "1":
  38. {
  39. "dtfrom":"2017-12-13",
  40. "dtto":"2017-12-13"
  41. }
  42. }
  43.  
  44. <?php
  45. $connect = mysqli_connect("", "", "", "");
  46. global $connect;
  47. if (isset($_POST['login']))
  48. {
  49. $login = $_POST['login'];
  50.  
  51. $sql = "SELECT * FROM users WHERE login='$login'";
  52. $result = mysqli_query($connect, $sql);
  53. if ($result && mysqli_num_rows($result) > 0) {
  54. while ($row = mysqli_fetch_array($result)) {
  55. $login_db = $row['login'];
  56. $email_db = $row['email'];
  57.  
  58. $output = array('login' => $login_db, 'email' => $email_db);
  59.  
  60. $sql2 = "SELECT * FROM movement WHERE user_id='$login_db'";
  61. $result2 = mysqli_query($connect, $sql2);
  62. if ($result2 && mysqli_num_rows($result2) > 0) {
  63. while ($row2 = mysqli_fetch_array($result2)) {
  64. $dtfromdb = $row2['dtfrom'];
  65. $dttodb = $row2['dtto'];
  66.  
  67. $output[] = array('dtfrom'=> $dtfromdb,'dtto'=> $dttodb);
  68.  
  69. }
  70. } else {}
  71. }
  72. echo json_encode($output);
  73. mysqli_free_result($result);
  74. }
  75. else { echo 'not found'; }
  76. }
  77. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement