vam1992
23.11.2008, 20:25
Am un script de Votare , fara baza de date din fisiere doar ... si vreau un ajutor de la voi .... ca sa il facem mai bun
Asa arata script-ul:
Va Place Site-ul?
Da 0 (0%)
Nu 0 (0%)
Add
Si vreau doar un mic upgrad la el , adica cand votezi sa nu deie tot omu de 1000000 de ori Vot , ci doar 1 data pe Ip! ca asa e frumos , pun scriptul mai jos , sper sa facem impreuna si treaba asta:biggrin:
<?php
// the questions and the answers
$pool_question="Va Place Site-ul?";
$pool_option[1]="Da";
$pool_option[2]="Nu";
// If counter files are not available,they will be created
// You may remove next lines after the first use of the script
if (!file_exists("pool_2430203_1.txt")){
// next two lines will not work if writing permissions are not available
// you may create the files bellow manualy with "0" as their unique content
file_put_contents ("pool_2430203_1.txt",0);
file_put_contents ("pool_2430203_2.txt",0);
}
// retrieve data saved in files
$pool_responses[1]=file_get_contents("pool_2430203_1.txt");
$pool_responses[2]=file_get_contents("pool_2430203_2.txt");
// if user votes, increase corresponding value
if ($_POST["2430203"] and $_POST["2430203b"]==""){
if ($_POST["2430203"]==1) {$pool_responses[1]++;file_put_contents("pool_2430203_1.txt",$pool_responses[1]);}
if ($_POST["2430203"]==2) {$pool_responses[2]++;file_put_contents("pool_2430203_2.txt",$pool_responses[2]);}
}
// get percentajes for each answer in the pool
// get total number of answers
$total_responses=$pool_responses[1]+$pool_responses[2];
if ($total_responses==0){$total_responses=1;} // to avoid errors at start
// compute percentajes (with one decimal number)
$pool_percentaje[1] = round((100*$pool_responses[1])/$total_responses,1);
$pool_percentaje[2] = round((100*$pool_responses[2])/$total_responses,1);
// print the form, which includes de answers and the percentajes
print "<center>\n";
print "<form method=post action=".$_SERVER["PHP_SELF"].">\n";
print "<b>".$pool_question."</b>\n";
print "<table cellpadding=4>\n";
// answer 1
print "<tr>\n";
print "<td><input type=radio name=2430203 value=1>* ".$pool_option[1]."</td>\n";
print "<td bgcolor=DDDDFF>".$pool_responses[1]." (".$pool_percentaje[1]."%)</td>\n";
print "</tr>\n";
// answer 2
print "<tr>\n";
print "<td><input type=radio name=2430203 value=2>* ".$pool_option[2]."</td>\n";
print "<td bgcolor=DDDDFF>".$pool_responses[2]." (".$pool_percentaje[2]."%)</td>\n";
print "</tr>\n";
print "</table>\n";
// a simple control to avoid one user to vote several times
if ($_POST["2430203"]){
print "<input type=hidden name=2430203b value=1>\n";
}
print "<input TYPE=submit value=Add my answer>\n";
print "</form>\n";
print "</center>\n";
?>
Asa arata script-ul:
Va Place Site-ul?
Da 0 (0%)
Nu 0 (0%)
Add
Si vreau doar un mic upgrad la el , adica cand votezi sa nu deie tot omu de 1000000 de ori Vot , ci doar 1 data pe Ip! ca asa e frumos , pun scriptul mai jos , sper sa facem impreuna si treaba asta:biggrin:
<?php
// the questions and the answers
$pool_question="Va Place Site-ul?";
$pool_option[1]="Da";
$pool_option[2]="Nu";
// If counter files are not available,they will be created
// You may remove next lines after the first use of the script
if (!file_exists("pool_2430203_1.txt")){
// next two lines will not work if writing permissions are not available
// you may create the files bellow manualy with "0" as their unique content
file_put_contents ("pool_2430203_1.txt",0);
file_put_contents ("pool_2430203_2.txt",0);
}
// retrieve data saved in files
$pool_responses[1]=file_get_contents("pool_2430203_1.txt");
$pool_responses[2]=file_get_contents("pool_2430203_2.txt");
// if user votes, increase corresponding value
if ($_POST["2430203"] and $_POST["2430203b"]==""){
if ($_POST["2430203"]==1) {$pool_responses[1]++;file_put_contents("pool_2430203_1.txt",$pool_responses[1]);}
if ($_POST["2430203"]==2) {$pool_responses[2]++;file_put_contents("pool_2430203_2.txt",$pool_responses[2]);}
}
// get percentajes for each answer in the pool
// get total number of answers
$total_responses=$pool_responses[1]+$pool_responses[2];
if ($total_responses==0){$total_responses=1;} // to avoid errors at start
// compute percentajes (with one decimal number)
$pool_percentaje[1] = round((100*$pool_responses[1])/$total_responses,1);
$pool_percentaje[2] = round((100*$pool_responses[2])/$total_responses,1);
// print the form, which includes de answers and the percentajes
print "<center>\n";
print "<form method=post action=".$_SERVER["PHP_SELF"].">\n";
print "<b>".$pool_question."</b>\n";
print "<table cellpadding=4>\n";
// answer 1
print "<tr>\n";
print "<td><input type=radio name=2430203 value=1>* ".$pool_option[1]."</td>\n";
print "<td bgcolor=DDDDFF>".$pool_responses[1]." (".$pool_percentaje[1]."%)</td>\n";
print "</tr>\n";
// answer 2
print "<tr>\n";
print "<td><input type=radio name=2430203 value=2>* ".$pool_option[2]."</td>\n";
print "<td bgcolor=DDDDFF>".$pool_responses[2]." (".$pool_percentaje[2]."%)</td>\n";
print "</tr>\n";
print "</table>\n";
// a simple control to avoid one user to vote several times
if ($_POST["2430203"]){
print "<input type=hidden name=2430203b value=1>\n";
}
print "<input TYPE=submit value=Add my answer>\n";
print "</form>\n";
print "</center>\n";
?>