Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include('../functions.php');
- include('../config.php');
- if(!ctype_digit($_GET['id'])) redirect('index.php');
- if(isLoggedIn() == 0) redirect('../login.php');
- //query poll details
- $query = mysql_query("SELECT poll_title,poll_question,date FROM polls WHERE id = '{$_GET['id']}'");
- if(mysql_num_rows($query) < 1)
- {
- //no poll exists with this ID
- redirect('index.php');
- }
- else
- {
- //extract poll details
- $extract = mysql_fetch_assoc($query);
- //query poll options
- $query_get_options = mysql_query("SELECT `id`,`option` FROM `poll_options` WHERE `belongs` = '{$_GET['id']}' ORDER BY `id` DESC");
- $total = getVoteTotal();
- while($row = mysql_fetch_assoc($query_get_options))
- {
- $query_get_votes = mysql_query("SELECT * FROM `votes` WHERE `option_id` = '{$row['id']}'");
- $num_of_results = mysql_num_rows($query_get_votes);
- ($num_of_results >= 1) ? $percentage = round(($num_of_results/$total))*100 : $percentage = '0';
- $content .= '
- <tr>
- <td class="shield" style="width: auto;"> '. $row['option'] .'</td>
- <td style="width: 20%;">'. $percentage .'% ('. $num_of_results .')</td>
- <td>
- <div id="poll"></div>
- </td>
- </tr>';
- }
- }
- function getVoteTotal()
- {
- //get # of votes
- $votes = mysql_query("SELECT * FROM votes WHERE poll = '{$_GET['id']}'");
- return mysql_num_rows($votes);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement