Help Us Choose A Girl's Name
Vote for a name
     
I want to submit a new name
Complete list of all names that were proposed
"); $filename = "namesip.txt"; $delimiter = ";"; $row = array(); if (($handle = fopen($filename, 'r')) !== FALSE) { while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) { echo("
"); for($i=0;$i<6;$i++) {echo("
" . $row[$i] . "
"); } echo("
"); } fclose($handle); } echo(""); } function read_the_list() { global $totalvotes; global $totalnames; global $nametext; global $namevotes; $myFile = "namescore.txt"; $file = fopen($myFile, 'r'); $i=0; $totalnames=0; $totalvotes=0; while (!feof($file)) { $newname= trim(fgets($file)); if (strlen($newname)) { $i=$i+1; $nametext[$i]=$newname; $totalnames=$totalnames+1; $votes=intval(trim(fgets($file))); $namevotes[$i] = $votes; $totalvotes=$totalvotes + $votes; } } fclose($file); } function write_the_list() { global $totalvotes; global $totalnames; global $nametext; global $namevotes; $sortme = array(); echo ("
Unique names: " . $totalnames . "
"); echo ("Total submissions: " . $totalvotes . "
"); echo("
Alphabetically sorted (Number of times name was proposed)
"); //--- display list on screen echo("
"); echo("
"); for ($i=1; $i<=$totalnames; $i=$i+1) { //echo ("
"); //echo ("
"); //$sortme[$i]=$namevotes[$i] . "x " . $nametext[$i] . " (" . intval(1000*$namevotes[$i]/$totalvotes)/10 . "%)"; $sortme[$i]= $nametext[$i] . " (" . $namevotes[$i] . "x)"; } sort($sortme); for ($i=0; $i<=$totalnames; $i=$i+4) { echo("
" . $sortme[$i] . "
"); echo("
" . $sortme[$i+1] . "
"); echo("
" . $sortme[$i+2] . "
"); echo("
" . $sortme[$i+3] . "
"); } echo ("
"); echo("
"); echo("
 
"); } function update_the_list($newname) { global $totalvotes; global $totalnames; global $nametext; global $namevotes; $name_exists=0; for ($i=1; $i<=$totalnames; $i=$i+1) { if (strcmp($nametext[$i], $newname)==0) { $namevotes[$i]=$namevotes[$i]+1; $totalvotes=$totalvotes+1; $name_exists=1; } } if($name_exists==0) { $totalnames=$totalnames+1; $nametext[$totalnames]=$newname; $namevotes[$totalnames]=1; $totalvotes=$totalvotes+1; echo("
". $newname ." added to list!
"); } else {echo("
You voted for " . $newname ." !
"); } //--- rewrite the file contents $myFile = "namescore.txt"; $fh = fopen($myFile, 'w+') or die("can't open file"); for ($i=1; $i<=$totalnames; $i=$i+1) { fwrite($fh, $nametext[$i]); fwrite($fh, "\r\n"); fwrite($fh, $namevotes[$i]); fwrite($fh, "\r\n"); } fclose($fh); } ?>