Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.22 KB | None | 0 0
  1.  
  2.  
  3.  
  4. <?php
  5.  session_start();
  6. include_once 'connectdb.php';
  7.  
  8.  
  9.   $tsres = mysqli_query($conn, "SELECT COUNT(admno) FROM students ");
  10.    
  11.   $scount = mysqli_fetch_array($tsres);
  12.    
  13. //get the number of total expected voter for every position
  14.  $total_expected_voters = $scount[0];
  15.  
  16. //get the number of total voters  multiply by 11
  17. $total_expected_votes  = 11 * $total_expected_voters ;
  18.  
  19. // count total casted ballots
  20.   $bres = mysqli_query($conn, "SELECT COUNT(BallotNo) FROM polls ");
  21.    
  22.   $bcount = mysqli_fetch_array($bres);
  23.    
  24. $total_casted_ball = $bcount[0];
  25. $p_total_casted_ball = $total_casted_ball/$total_expected_votes;
  26.  
  27. // count total valid ballots
  28.    $vbres = mysqli_query($conn, "SELECT COUNT(Position) FROM polls WHERE candidate <> 'None'");
  29.    
  30.   $vbcount = mysqli_fetch_array($vbres);
  31.    
  32.  $total_valid_casted_ball = $vbcount[0];
  33.             $ptvball = $total_valid_casted_ball/$total_casted_ball * 100;
  34.  $p_total_valid_casted_ball = round($ptvball);
  35.  
  36. //count total spoilt votes votes
  37. $total_null_ball = $total_casted_ball - $total_valid_casted_ball;
  38.         $p_total_null_ball = $total_null_ball / $total_casted_ball * 100;
  39. $p_total_null_ball = round($p_total_null_ball );
  40.  
  41.  
  42. //THE FUNCTION
  43.  
  44. function getvotes( $x ){
  45.  
  46.   //it has flatly refused to inlcude the connect db file. i had to manual paste the code here
  47.     //include_once 'connectdb.php';
  48.  error_reporting( ~E_DEPRECATED & ~E_NOTICE );
  49.  
  50. $hostname = "localhost";
  51. $user = "root";
  52. $password = "";
  53. $mysql_database = "dbiesrvoting";
  54. $prefix = "";
  55.  
  56. $conn = mysqli_connect($hostname, $user, $password) or die("Could not connect to mysql");
  57. mysqli_select_db($conn, $mysql_database) or die("Could not select database");
  58.    
  59.     //puts all position in a strinG variable for easy debugging
  60.     $c = "Chairperson";
  61.     $vc ="Vice Chairperson";
  62.     $sg ="Secretary General";
  63.     $fs ="Finance Secretary";
  64.     $eds ="Education Secretary";
  65.     $des ="Deputy Education Secretary";
  66.     $sas ="Social Affairs Secretary";
  67.     $dsas ="Deputy Social Affairs Secretary";
  68.     $lr ="Ladies Representative";
  69.     $hns ="Health and Nutrition Secretary";
  70.     $es ="Environment Secretary";
  71.  
  72.        
  73. if ($x == "c"){
  74. $position =  "Chairperson";
  75. }elseif ($x =="vc"){    
  76. $position = $vc;  
  77. }
  78. elseif ($x =="sg"){
  79. $position = $sg;
  80. }
  81. elseif ($x =="fs"){    
  82. $position = $fs;    
  83. }      elseif ($x =="eds"){
  84. $position = $eds;    
  85. } elseif ($x =="des"){  
  86. $position = $des;  
  87. }      elseif ($x =="sas"){    
  88. $position = $sas;      
  89. }      elseif ($x =="dsas"){
  90. $position = $dsas;  
  91. }      elseif ($x =="lr"){
  92. $position = $lr;
  93.  
  94. }     elseif ($x =="hns"){
  95. $position = $hns;
  96.  
  97. }      elseif ($x =="es"){
  98. $position = $es;    
  99. }
  100.    
  101.  
  102.    
  103.   // count total casted ballots for specified position
  104.   $tres = mysqli_query($conn, "SELECT COUNT(Candidate) FROM polls where position  = '$position'");
  105.    
  106.   $tcount = mysqli_fetch_array($tres);
  107.    
  108. $t = $tcount[0];
  109.    
  110.      // count total casted ballots for specified position with none votes.
  111.  $tres = mysqli_query($conn, "SELECT COUNT(Candidate) FROM polls where position  = '$position' and candidate = 'None'");
  112.    
  113.   $tcount = mysqli_fetch_array($tres);
  114.    
  115. $n = $tcount[0];
  116.    
  117.    
  118.      // get the null votes. Null is total position vote - valid position vote.
  119.   $v = $t -$n ;
  120.    
  121.    
  122.  echo "  $position <br/>";    
  123.   echo " total: $t <br/>";
  124.     echo "valid $v <br/>";
  125.      echo "null $n <br/>";
  126.    
  127.    
  128.     mysqli_close($conn);
  129.  
  130. }
  131.  
  132. ?>
  133. <div>
  134. <?  getvotes(c ); ?>
  135. </div><br />
  136.  
  137.  
  138. <div>
  139. <?  getvotes(vc ); ?>
  140. </div><br />
  141.  
  142.  
  143. <div>
  144. <?  getvotes(sg ); ?>
  145. </div><br />
  146.  
  147. <div>
  148. <?  getvotes(fs ); ?>
  149. </div><br />
  150.  
  151.  
  152. <div>
  153. <?  getvotes(eds ); ?>
  154. </div><br />
  155.  
  156.  
  157. <div>
  158. <?  getvotes(des ); ?>
  159. </div><br />
  160. <div>
  161. <?  getvotes(sas ); ?>
  162. </div><br />
  163.  
  164.  
  165. <div>
  166. <?  getvotes(dsas ); ?>
  167. </div><br />
  168.  
  169.  
  170. <div>
  171. <?  getvotes(lr ); ?>
  172. </div><br />
  173. <div>
  174. <?  getvotes(hns ); ?>
  175. </div><br />
  176.  
  177.  
  178. <div>
  179. <?  getvotes(es ); ?>
  180. </div><br />
  181.  
  182.  
  183. <div>
  184. <?  echo "total valid is $total_valid_casted_ball"; ?>
  185. </div><br />
  186. <div>
  187. <?  echo "total null is $total_null_ball"; ?>
  188. </div><br />
  189. <div>
  190. <?  echo "total votes is $total_casted_ball"; ?>
  191. </div><br />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement