You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.3 KiB

  1. <?php
  2. /**
  3. * Ambil data masing masing calon beserta suara yang didapatkan
  4. * dengan format layaknya hasil Query Builder di Laravel. Seperti:
  5. *
  6. * Calon 1 => [
  7. * nama => ...
  8. * suara => [
  9. * valid => ...
  10. * tidak valid => ...
  11. * ]
  12. * ]
  13. */
  14. require_once('../conn/db.php');
  15. require_once('../utils/helper.php');
  16. $result = [];
  17. // Ambil profil calon senat
  18. $queryCandidatesSenat = "SELECT
  19. id_calon,
  20. nama_calon,
  21. photo,
  22. id_status
  23. FROM
  24. tb_calon
  25. WHERE id_status='KTU3vVnd'
  26. ORDER BY photo";
  27. $execCandidatesSenat = odbc_exec($koneksi, $queryCandidatesSenat);
  28. $candidatesSenat = dbGet($execCandidatesSenat);
  29. // Ambil profil calon balma
  30. $queryCandidatesBalma = "SELECT
  31. id_calon,
  32. nama_calon,
  33. photo,
  34. id_status
  35. FROM
  36. tb_calon
  37. WHERE id_status='S9af54pY'
  38. ORDER BY photo";
  39. $execCandidatesBalma = odbc_exec($koneksi, $queryCandidatesBalma);
  40. $candidatesBalma = dbGet($execCandidatesBalma);
  41. $queryStudents = "SELECT TOP 625
  42. nim,
  43. nama,
  44. pass
  45. FROM
  46. tb_mhs";
  47. $execStudents = odbc_exec($koneksi, $queryStudents);
  48. $students = dbGet($execStudents);
  49. $array = [];
  50. $i = 1;
  51. foreach ($students as $student) {
  52. $senat_random_number = mt_rand(0, 2);
  53. $balma_random_number = mt_rand(0, 1);
  54. $senat = $candidatesSenat[$senat_random_number];
  55. $balma = $candidatesBalma[$balma_random_number];
  56. odbc_autocommit($koneksi, FALSE);
  57. $stmt1 = odbc_prepare($koneksi, 'INSERT INTO tb_pemilu (id_calon,id_status,nim_mhs,ip) values (?, ?, ?, ?)');
  58. $stmt2 = odbc_prepare($koneksi, 'INSERT INTO tb_pemilu (id_calon,id_status,nim_mhs,ip) values (?, ?, ?, ?)');
  59. $values1 = array($i++,$senat['id_calon'], $senat['id_status'], $student['nim'], "::1");
  60. $values2 = array($i++,$balma['id_calon'], $balma['id_status'], $student['nim'], "::1");
  61. // $exec0 = odbc_execute($stmt1, $values1);
  62. // $exec1 = odbc_execute($stmt2, $values2);
  63. // if (!odbc_error()) {
  64. // odbc_commit($koneksi);
  65. // } else {
  66. // odbc_rollback($koneksi);
  67. // }
  68. array_push($array, $values1);
  69. array_push($array, $values2);
  70. }
  71. // odbc_close($koneksi);
  72. dump($array);
  73. // Atur header demi JSON
  74. // dump($candidates);