//CMXads.com Unlimited Polls for your website noSQL
//Addon Utility Php Script demo tutorial example
//Legal to use with visible display of credit and link to cmxads.com
//Copyright 2021 by George CMXads.com
//PHP INCLUDE THIS IN PAGE WHERE POLL IS RUNNING
'Do you like to take a poll?');
$poll_options_1 =array('No. But my boy friend does.',
'No. But my girl friend does.',
'Yes. I take every poll I can.',
'Sometimes. If I like the poll.',
'Yes. I take poles in the bum.');
///////////////////// END INCLUDE
?>
$choice_id, 'cnt'=> '1' , 'option' =>$poll_options_1[$choice_id]));
$input= json_encode($input);
if( file_put_contents( $to_file, $input)){
$error='';
}
}
// if file exists and has entries
if (file_exists($to_file) && filesize($to_file) >4){
$f_out = file_get_contents($to_file);// read file
$f_out = json_decode($f_out, true);// json decode
$found='';// initiate flag variable if we found selected option already in array
$i='0';// starting array key at 0
foreach($f_out as $opt) {//f_out array to arrays of poll options
// foreach loop the inner level options array
// each option has choice number(key), vote count and option text
foreach($opt as $key=>$value)
{
//if match on posted choice and array choice
if($key == 'choice' && $value == $choice_id){
// flag found set. So we know not to add a new choice option to array
$found='1';
//echo $key." ". $value. "
";
//echo $f_out[$i]['cnt']. "
";
$opt['cnt'] += '1';// get the count of that choice option and add 1
}
}
//in loop with $i number update $f_out array count for that choice option
$f_out[$i]['cnt']=$opt['cnt'];
$i++;
}
if($found){// we updated option vote count above
$input= json_encode($f_out);// encode
if( file_put_contents( $to_file, $input)){// write back to file
$error='';
}
}
if(!$found){// we must add the new chosen option to array
// the new pushed array is the posted choice key, count=1
//and pull poll option text from options array
$input2 = array('choice' =>$choice_id, 'cnt'=> '1' , 'option' => $poll_options_1[$choice_id]);
array_push($f_out, $input2);// push new array into array
$input= json_encode($f_out);// encode
if(file_put_contents( $to_file, $input)){// write back to file
$error='';
}
}
if(!$error){
//echo '
'; //$f_out = file_get_contents($to_file);// read and process results // $f_out = json_decode($f_out, true);// json decode //var_dump( $f_out); // echo ''; //exit; } } } ?> 5){ $f_out = file_get_contents($poll_file);// read file $f_out = json_decode($f_out, true);// decode //now we want to process the data to get the votes //and calculate the percentages of the total votes to options $all_votes=0;// initialize variable foreach($f_out as $choice){ // first calculate totalvote in loop $all_votes += $choice['cnt']; } if($all_votes==0) { print "No votes have been casted.