Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- include_once 'connectdb.php';
- $tsres = mysqli_query($conn, "SELECT COUNT(admno) FROM students ");
- $scount = mysqli_fetch_array($tsres);
- //get the number of total expected voter for every position
- $total_expected_voters = $scount[0];
- //get the number of total voters multiply by 11
- $total_expected_votes = 11 * $total_expected_voters ;
- // count total casted ballots
- $bres = mysqli_query($conn, "SELECT COUNT(BallotNo) FROM polls ");
- $bcount = mysqli_fetch_array($bres);
- $total_casted_ball = $bcount[0];
- $p_total_casted_ball = $total_casted_ball/$total_expected_votes;
- // count total valid ballots
- $vbres = mysqli_query($conn, "SELECT COUNT(Position) FROM polls WHERE candidate <> 'None'");
- $vbcount = mysqli_fetch_array($vbres);
- $total_valid_casted_ball = $vbcount[0];
- $ptvball = $total_valid_casted_ball/$total_casted_ball * 100;
- $p_total_valid_casted_ball = round($ptvball);
- //count total spoilt votes votes
- $total_null_ball = $total_casted_ball - $total_valid_casted_ball;
- $p_total_null_ball = $total_null_ball / $total_casted_ball * 100;
- $p_total_null_ball = round($p_total_null_ball );
- //THE FUNCTION
- function getvotes( $x ){
- //it has flatly refused to inlcude the connect db file. i had to manual paste the code here
- //include_once 'connectdb.php';
- error_reporting( ~E_DEPRECATED & ~E_NOTICE );
- $hostname = "localhost";
- $user = "root";
- $password = "";
- $mysql_database = "dbiesrvoting";
- $prefix = "";
- $conn = mysqli_connect($hostname, $user, $password) or die("Could not connect to mysql");
- mysqli_select_db($conn, $mysql_database) or die("Could not select database");
- //puts all position in a strinG variable for easy debugging
- $c = "Chairperson";
- $vc ="Vice Chairperson";
- $sg ="Secretary General";
- $fs ="Finance Secretary";
- $eds ="Education Secretary";
- $des ="Deputy Education Secretary";
- $sas ="Social Affairs Secretary";
- $dsas ="Deputy Social Affairs Secretary";
- $lr ="Ladies Representative";
- $hns ="Health and Nutrition Secretary";
- $es ="Environment Secretary";
- if ($x == "c"){
- $position = "Chairperson";
- }elseif ($x =="vc"){
- $position = $vc;
- }
- elseif ($x =="sg"){
- $position = $sg;
- }
- elseif ($x =="fs"){
- $position = $fs;
- } elseif ($x =="eds"){
- $position = $eds;
- } elseif ($x =="des"){
- $position = $des;
- } elseif ($x =="sas"){
- $position = $sas;
- } elseif ($x =="dsas"){
- $position = $dsas;
- } elseif ($x =="lr"){
- $position = $lr;
- } elseif ($x =="hns"){
- $position = $hns;
- } elseif ($x =="es"){
- $position = $es;
- }
- // count total casted ballots for specified position
- $tres = mysqli_query($conn, "SELECT COUNT(Candidate) FROM polls where position = '$position'");
- $tcount = mysqli_fetch_array($tres);
- $t = $tcount[0];
- // count total casted ballots for specified position with none votes.
- $tres = mysqli_query($conn, "SELECT COUNT(Candidate) FROM polls where position = '$position' and candidate = 'None'");
- $tcount = mysqli_fetch_array($tres);
- $n = $tcount[0];
- // get the null votes. Null is total position vote - valid position vote.
- $v = $t -$n ;
- echo " $position <br/>";
- echo " total: $t <br/>";
- echo "valid $v <br/>";
- echo "null $n <br/>";
- mysqli_close($conn);
- }
- ?>
- <div>
- <? getvotes(c ); ?>
- </div><br />
- <div>
- <? getvotes(vc ); ?>
- </div><br />
- <div>
- <? getvotes(sg ); ?>
- </div><br />
- <div>
- <? getvotes(fs ); ?>
- </div><br />
- <div>
- <? getvotes(eds ); ?>
- </div><br />
- <div>
- <? getvotes(des ); ?>
- </div><br />
- <div>
- <? getvotes(sas ); ?>
- </div><br />
- <div>
- <? getvotes(dsas ); ?>
- </div><br />
- <div>
- <? getvotes(lr ); ?>
- </div><br />
- <div>
- <? getvotes(hns ); ?>
- </div><br />
- <div>
- <? getvotes(es ); ?>
- </div><br />
- <div>
- <? echo "total valid is $total_valid_casted_ball"; ?>
- </div><br />
- <div>
- <? echo "total null is $total_null_ball"; ?>
- </div><br />
- <div>
- <? echo "total votes is $total_casted_ball"; ?>
- </div><br />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement