Home > Backend Development > PHP Tutorial > Online survey program code_PHP tutorial

Online survey program code_PHP tutorial

WBOY
Release: 2016-07-13 10:57:41
Original
1322 people have browsed it

No database required for online polling survey php code This is an online voting system made of php + txt text files. It can complete online user survey functions without database support.



Online survey program code



Survey item one


Survey item 2


Survey item three


Survey item four


Survey item five




View results


//survey.php

/*
No database tutorial online poll php code
This is an online voting system made of php + txt text files. It can complete online user survey functions without database support.
*/
$data="data.txt";
$votes="survey.txt";
$dataf=file($data); /*Read the items in the survey project file*/
$file_votes=fopen($votes, "r");
$line_votes=fgets($file_votes, 255); /*Read the recorded survey results*/
fclose($file_votes);
$single_vote=explode("|", $line_votes); /* Split the data according to the specified string, and then transfer the string back to the array variable */
if ($result!=1) /*If the survey has been accepted*/
{
$file_votes=file($votes, "r");
if ($remote_addr == $file_votes[1]) /*Check if they are the same person*/
          {
echo "

You have already voted, thank you for your participation!
";
exit;
}

/*If the IP is not repeated, execute the following procedure*/
$ficdest=fopen($votes, "w");
for ($i=0; $i<=count($dataf)-1; $i++)
          {
             if ($i == $vote)
                                                                                                                                                                                                                                                             $single_vote[$i]+=1;
           }
                  fputs($ficdest, "$single_vote[$i]|"); /*Write data back to file*/
        }
           fputs($ficdest, "n$remote_addr");/* //Write the voter ip*/
fclose($ficdest);
$result=1; /*Vote successful*/
}

/*Write the voting results and display the voting results*/
if ($result==1)
{
echo "

";
for ($i=0; $i<=count($dataf)-1; $i++)
{
/*Get the total number of votes*/
$tot_votes+=$single_vote[$i];
}
for ($i=0; $i<=count($dataf)-1; $i++)
{
$imag=strval($i).".gif";/*Determine which bar picture to use to display statistical results*/
$stat[$i]=$single_vote[$i]/$tot_votes*100; /*Calculate percentage*/
$scla=$stat[$i]*5;/*Bar chart and magnification, here it is displayed by the width of the pixel that is 5 times the percentage of ampere*/
echo "";
}
echo "
  • ";
    echo "$dataf[$i]
  • ";
    echo " ";/*Output barcode image*/
    Printf("%.1f", "$stat[$i]");
    echo "%
    ";
    /*Output the number of votes for this column*/
    echo "$single_vote[$i]
    ";
    echo "

    ";
    echo "Total votes: $tot_votes ";
    }

    /*
    data.txt file
    Survey item one
    Survey item two
    Survey item three
    Survey item four
    Survey item five
    */
    ?>

    www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632061.htmlTechArticleNo database required online voting survey php code This is an online calling voting system made of php + txt text file. The online user survey function can be completed without database support. html head...
    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template