First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing!
Search tutorials
Author: Mirza Hatipovic


\n
"; //select question + all possible answers //first we must find the id of the last inserted question $db_data = mysql_fetch_array(mysql_query("SELECT MAX(poll_id) AS max_id FROM anketa_pit")); //id of the last question $last_que_id = $db_data[max_id]; //questions $rez = mysql_query("SELECT pitanje FROM anketa_pit WHERE poll_id = ".$last_que_id); //fetch question $question_data = mysql_fetch_array($rez); //add question to form $poll_form .= "".$question_data[pitanje]."
"; //oslobodi memoriju mysql_free_result($rez); //get all possible answers $rez = mysql_query("SELECT odg_id, odgovor FROM anketa_odg WHERE poll_id = ".$last_que_id); //counter variable $i = 0; //fetch answer from db and add them to form while($anwer_data = mysql_fetch_array($rez)){ //current status of the radio button, checked or unchecked??? ++$i == 1 ? $status = "checked" : $status = ""; //concate radio buttons $poll_form .= " ".$anwer_data[odgovor]."
\n"; } //add submit button $poll_form .= "\n"; //complete form tag $poll_form .= "\n"; //if the poll form is submitted if($REQUEST_METHOD == "POST"){ //register voter to deny more votes session_register("vote_request"); //update table mysql_query("UPDATE anketa_odg SET hits = hits + 1 WHERE odg_id = ".$_POST[answer]); //get values from db and show it in swf //first we must find the id of the last inserted question $db_data = mysql_fetch_array(mysql_query("SELECT MAX(poll_id) AS max_id FROM anketa_pit")); //id of the last question $last_que_id = $db_data[max_id]; //get question $rez = mysql_query("SELECT pitanje FROM anketa_pit WHERE poll_id = ".$last_que_id); //fetch question $question_data = mysql_fetch_array($rez); $question = $question_data[pitanje]; //get num of all answers to that question $rez = mysql_query("SELECT SUM(hits) as all_hits FROM anketa_odg WHERE poll_id = ".$last_que_id); //fetch result $data = mysql_fetch_array($rez); //num of all hits $num_ans = $data[all_hits]; //free some memory mysql_free_result($rez); //get all possible answers $rez = mysql_query("SELECT odgovor, hits FROM anketa_odg WHERE poll_id = ".$last_que_id); //counter variable $i = 1; //init. flash vars $flash_vars = "question=".$question."&"; //fetch answer from db and add them to form while($ans_dta = mysql_fetch_array($rez)){ $flash_vars .= "odgovor".$i."=".$ans_dta[odgovor]."&proc".$i."=".round((intval($ans_dta[hits])/intval($num_ans))*100)."&br_gl".$i."=".$ans_dta[hits]."&"; $i++; } //free some memory mysql_free_result($rez); //pokreni pop up zajedno sa varijablama echo ""; //zapamti varijable session_register("flash_vars"); echo "view results"; } else { //add form or link to template echo $poll_form; } } else { //show link to view only the results echo "view results"; } ?>

That’s the code required for the poll, if you want to use it as a module on a page, simply put the code above into your own php script and separate it with blocks, like this:

» Level Advanced

Added: 2003-07-21
Rating: 6.75 Votes: 84
(10 being the highest)
» Author
Mirza Hatipovic is freelance developer based in Bosnia and Hercegovina. He uses Flash MX, PHP, XML amd Coldfusion to create dynamic web content.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.