Jump to content

how should i code this polling system?


dadamssg

Recommended Posts

I've coded the form and and scripts to enter in the votes but now im wondering what the most efficient way of pulling the info for each poll out to display. I have coded it to allow me to put at minimum two answer options and up to five. I just want to figure out the percentages each option gets. I'm thinkin theres a more effective way than doing it somethin like this

$cxn = mysqli_connect($host,$user,$passwd,$dbname) or die("Couldn't connect");
         $sqz = "select * from poll_votes where pq_id = '$row['pq_id']'";
         $resultz = mysqli_query($cxn,$sqz)
          or die (mysqli_error($cxn)); 
         $all_votes = mysqli_num_rows($resultz);

	 $sqq = "select * from poll_votes where pq_id = '$row['pq_id']' and vote = '1'";
         $resultq = mysqli_query($cxn,$sqq)
          or die (mysqli_error($cxn)); 
         $num_1_votes = mysqli_num_rows($resultq);

$sqb = "select * from poll_votes where pq_id = '$row['pq_id']' and vote = '2'";
         $resultb = mysqli_query($cxn,$sqb)
          or die (mysqli_error($cxn)); 
         $num_2_votes = mysqli_num_rows($resultb);

$sqt = "select * from poll_votes where pq_id = '$row['pq_id']' and vote = '3'";
         $resultt = mysqli_query($cxn,$sqt)
          or die (mysqli_error($cxn)); 
         $num_3_votes = mysqli_num_rows($resultt);

$sq4 = "select * from poll_votes where pq_id = '$row['pq_id']' and vote = '4'";
         $result4 = mysqli_query($cxn,$sq4)
          or die (mysqli_error($cxn)); 
         $num_4_votes = mysqli_num_rows($result4);

$sq5 = "select * from poll_votes where pq_id = '$row['pq_id']' and vote = '5'";
         $result5 = mysqli_query($cxn,$sq5)
          or die (mysqli_error($cxn)); 
         $num_5_votes = mysqli_num_rows($result5);

//math code to figure percentages here....

 

Link to comment
https://forums.phpfreaks.com/topic/186891-how-should-i-code-this-polling-system/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.