Guest User

Fetching of Data

a guest
Mar 6th, 2023
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. ``` // The first query that will execute to get the students in database ('Added By: Ron Ivin Gregorio - 02/20/2023')
  2. const getAllCustomer = async () => {
  3. let skip = 0;
  4. let final_array_count = 0;
  5. $('.customers-list').empty();
  6.  
  7. try {
  8.  
  9. do{
  10.  
  11. const data = {
  12. 'search' : search,
  13. 'advanced_search': advanced_search,
  14. 'order': order,
  15. 'sort': sort,
  16. 'skip': skip
  17. };
  18.  
  19. const response = await fetch('process/get_all_customers.php', {
  20. method: "POST",
  21. headers: {
  22. "Content-Type": "application/json"
  23. },
  24. body: JSON.stringify(data)
  25. });
  26.  
  27. const result = await response.json();
  28. if (result.status) {
  29.  
  30. if (0 < result.c_length) {
  31. final_array_count = result.c_length;
  32. skip += 20;
  33. } else {
  34.  
  35. final_array_count = final_array_count - 20;
  36. let minus = final_array_count
  37.  
  38. if (minus < 20) {
  39. skip += minus;
  40. } else {
  41. skip += 20;
  42. }
  43.  
  44. }
  45.  
  46. if(0 < result.data.length){
  47. let count = 0;
  48. let num = $('.row_link').length;
  49. result.data.forEach((value) => {
  50. let x = '<tr id="row_link'+num+'" class="row_link" cid= "'+value['id']+'">';
  51. x += '<td>' + ++num +'</td>';
  52. x += '<td class="timestamp">' + value['registration_date'] + '<br>' + value['registration_time'] +'</td>';
  53. x += '<td>' + value ['name'] +'</td>';
  54. x += '<td>' + value ['dlnum'] +'</td>';
  55. x += '<td>' + value ['student_ids'] +'</td>';
  56. x += '<td>' + value ['courses'] +'</td>';
  57. x += '<td>' + value ['classes'] +'</td>';
  58. x += '<td>' + value ['affiliates'] +'</td>';
  59. x += '<td>' + value ['companies'] +'</td>';
  60. x += '<td>' + value ['status'] +'</td>';
  61. x += '</tr>';
  62. $('.customers-list').append(x)
  63. count++;
  64. });
  65.  
  66. }
  67.  
  68. }
  69.  
  70. }while(0 < final_array_count);
  71.  
  72. let num = $('.row_link').length;
  73.  
  74. if(num < 20){
  75. let add_row = 20 - num;
  76. for(let x = 0; x < add_row; x++){
  77. let y = '<tr>';
  78. y += '<td></td>';
  79. y += '<td></td>';
  80. y += '<td></td>';
  81. y += '<td></td>';
  82. y += '<td></td>';
  83. y += '<td></td>';
  84. y += '<td></td>';
  85. y += '<td></td>';
  86. y += '<td></td>';
  87. y += '<td></td>';
  88. y += '</tr>';
  89. $('.customers-list').append(y)
  90. }
  91. }
  92.  
  93. } catch (error) {
  94. // console.log(error.message)
  95. let num = $('.row_link').length;
  96.  
  97. if(num < 20){
  98. let add_row = 20 - num;
  99. for(let x = 0; x < add_row; x++){
  100. let y = '<tr>';
  101. y += '<td></td>';
  102. y += '<td></td>';
  103. y += '<td></td>';
  104. y += '<td></td>';
  105. y += '<td></td>';
  106. y += '<td></td>';
  107. y += '<td></td>';
  108. y += '<td></td>';
  109. y += '<td></td>';
  110. y += '<td></td>';
  111. y += '</tr>';
  112. $('.customers-list').append(y)
  113. }
  114. }
  115. }
  116.  
  117. }
  118.  
  119. getAllCustomer(); ```
Advertisement
Add Comment
Please, Sign In to add comment