Advertisement
Guest User

Untitled

a guest
Mar 8th, 2012
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. <?php
  2. include('../functions.php');
  3. include('../config.php');
  4.  
  5. if(!ctype_digit($_GET['id'])) redirect('index.php');
  6. if(isLoggedIn() == 0) redirect('../login.php');
  7.  
  8. //query poll details
  9. $query = mysql_query("SELECT poll_title,poll_question,date FROM polls WHERE id = '{$_GET['id']}'");
  10.  
  11. if(mysql_num_rows($query) < 1)
  12. {
  13.     //no poll exists with this ID
  14.     redirect('index.php');
  15. }
  16. else
  17. {
  18.     //extract poll details
  19.     $extract = mysql_fetch_assoc($query);
  20.        
  21.     //query poll options
  22.     $query_get_options = mysql_query("SELECT `id`,`option` FROM `poll_options` WHERE `belongs` = '{$_GET['id']}' ORDER BY `id` DESC");
  23.  
  24.     $total = getVoteTotal();
  25.    
  26.     while($row = mysql_fetch_assoc($query_get_options))
  27.     {
  28.         $query_get_votes = mysql_query("SELECT * FROM `votes` WHERE `option_id` = '{$row['id']}'");
  29.         $num_of_results = mysql_num_rows($query_get_votes);
  30.        
  31.         ($num_of_results >= 1) ? $percentage = round(($num_of_results/$total))*100 : $percentage = '0';
  32.  
  33.         $content .= '
  34.         <tr>
  35.         <td class="shield" style="width: auto;">&nbsp;'. $row['option'] .'</td>
  36.         <td style="width: 20%;">'. $percentage .'% ('. $num_of_results .')</td>
  37.         <td>
  38.             <div id="poll"></div>
  39.         </td>
  40.         </tr>';
  41.     }
  42. }
  43.  
  44. function getVoteTotal()
  45. {
  46.     //get # of votes
  47.     $votes = mysql_query("SELECT * FROM votes WHERE poll = '{$_GET['id']}'");
  48.    
  49.     return mysql_num_rows($votes);
  50. }
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement