Forum Moderators: coopster

Message Too Old, No Replies

PHP Algorithm for counting votes

PHP vote count

         

bobbyorio

4:49 pm on Feb 25, 2004 (gmt 0)



PHP Counting algorithm for voting system

--------------------------------------------------------------------------------

Hi I am an irish student, this is my first post and I am sorry for it being so long.

My project is to simulate an electronic voting system for Irish government elections using proportional representation.

The project is almost comlete bar the actual counting algorithm. I have a ballot table which stores each individual ballot where the primary key is ballotId which starts at 0 and increments automatically everytime someone votes in effect adding a row to the table. The other keys are firstPref which stores a unique idNum which is the primary key for a candidate in the candidate table and this cant be null(as for a valid ballot it must have at least a first Preference). Also there are keys for secondPref, thirdPref and fourthPref. These can be NULL but for a valid ballot if you select thirdPref NULL then fourthPref has to be NULL or if secondPref was selected as NULL then of course thirdPref and fouthPref have to be NULL. The votes are going into the ballot table correctly and all the ballots are valid.

What I need is an algorithm to look through the ballot table and determine which two candidates are elected through proportional representation. I understand how it works in English but cant make sense of it in PHP as its my first time using it. I would really appreciate any help.

Thanks,

Bobby

P.S if you arent familiar with proportional representation go to [oasis.gov.ie...]

coopster

2:39 am on Feb 27, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, bobbyorio!

No takers yet? This may be easier if we break it down into pieces so I'll try to help get the ball rolling by calculating the quota:

<?php 
$number_of_seats = 4;
$sql = "SELECT FLOOR(COUNT(*)/($number_of_seats + 1) + 1) FROM ballots";
?>

You didn't mention which database you were using...?