Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

90 rader
2.3 KiB

<?php
/**
* Ambil data masing masing calon beserta suara yang didapatkan
* dengan format layaknya hasil Query Builder di Laravel. Seperti:
*
* Calon 1 => [
* nama => ...
* suara => [
* valid => ...
* tidak valid => ...
* ]
* ]
*/
require_once('../conn/db.php');
require_once('../utils/helper.php');
$result = [];
// Ambil profil calon senat
$queryCandidatesSenat = "SELECT
id_calon,
nama_calon,
photo,
id_status
FROM
tb_calon
WHERE id_status='KTU3vVnd'
ORDER BY photo";
$execCandidatesSenat = odbc_exec($koneksi, $queryCandidatesSenat);
$candidatesSenat = dbGet($execCandidatesSenat);
// Ambil profil calon balma
$queryCandidatesBalma = "SELECT
id_calon,
nama_calon,
photo,
id_status
FROM
tb_calon
WHERE id_status='S9af54pY'
ORDER BY photo";
$execCandidatesBalma = odbc_exec($koneksi, $queryCandidatesBalma);
$candidatesBalma = dbGet($execCandidatesBalma);
$queryStudents = "SELECT TOP 625
nim,
nama,
pass
FROM
tb_mhs";
$execStudents = odbc_exec($koneksi, $queryStudents);
$students = dbGet($execStudents);
$array = [];
$i = 1;
foreach ($students as $student) {
$senat_random_number = mt_rand(0, 2);
$balma_random_number = mt_rand(0, 1);
$senat = $candidatesSenat[$senat_random_number];
$balma = $candidatesBalma[$balma_random_number];
odbc_autocommit($koneksi, FALSE);
$stmt1 = odbc_prepare($koneksi, 'INSERT INTO tb_pemilu (id_calon,id_status,nim_mhs,ip) values (?, ?, ?, ?)');
$stmt2 = odbc_prepare($koneksi, 'INSERT INTO tb_pemilu (id_calon,id_status,nim_mhs,ip) values (?, ?, ?, ?)');
$values1 = array($i++,$senat['id_calon'], $senat['id_status'], $student['nim'], "::1");
$values2 = array($i++,$balma['id_calon'], $balma['id_status'], $student['nim'], "::1");
// $exec0 = odbc_execute($stmt1, $values1);
// $exec1 = odbc_execute($stmt2, $values2);
// if (!odbc_error()) {
// odbc_commit($koneksi);
// } else {
// odbc_rollback($koneksi);
// }
array_push($array, $values1);
array_push($array, $values2);
}
// odbc_close($koneksi);
dump($array);
// Atur header demi JSON
// dump($candidates);