[POLL] Automatisch meeste stemmen bovenaan

  • Onderwerp starter Onderwerp starter EWP
  • Startdatum Startdatum
Status
Niet open voor verdere reacties.

EWP

Gebruiker
Lid geworden
28 feb 2009
Berichten
17
Geachte forumleden,

Wij hebben een Poll script waar mensen op kunnen stemmen (logisch). Maar nu willen we dat de optie met de meeste stemmen boven aan komt.

Zodat we goed kunnen zien waarop het meest gestemd is.
Dit is de server side script.
PHP:
<?php

if ($totalpolls > 0) {

	if (!isset ($_REQUEST['option']) && !isset ($_REQUEST['results']) && $votecookies != 'no' && $voteip != 'no' && $blocked != 'yes' && $started == 'yes' && $expired == 'no' && $polls['voting'] == 'yes') {
	
		$poll = mysql_fetch_array (mysql_query ("SELECT pollid, title, voting, results, graph FROM polls WHERE pollid='$whatpoll'"));

		$option = mysql_query ("SELECT optionid, options, order_id FROM options WHERE pollid='$whatpoll' ORDER BY order_id ASC");
	
?>
<form action="<?= $_SERVER['PHP_SELF']; ?>" method="post" name="frmPoll">
<table width="49%" border="0" cellspacing="0" cellpadding="2" class="border">
	<tr class="text">
		<td height="25" colspan="2" align="center"><b><?= $poll['title']; ?></b></td>
	</tr>
	<?php while ($optionrows = mysql_fetch_array ($option)) { ?>
	<tr class="text">
		<td width="10%" align="center" height="25"><input name="option" type="radio" value="<?= $optionrows['optionid']; ?>"<?php if ($optionrows['order_id'] == 1) { echo " CHECKED"; } ?>></td>
		<td width="90%"><?= $optionrows['options']; ?></td>
	</tr>
	<?php } ?>
	<tr>
		<td colspan="2" align="center" height="25"><input name="stage" type="hidden" value="2"><input name="poll" type="hidden" value="<?= $poll['pollid']; ?>"><input name="btnVote" type="submit" value="Stemmen" class="text"><br /><br />
		<?php if ($poll['results'] == 'yes' && $poll['graph'] == 'yes') { ?>
		<?php } ?></td>
	</tr>
</table>
</form>
<img src="images/layout/marker.gif" alt="" style="margin-right:3px; margin-left:1px; vertical-align:middle"><b><a href="?id=manofthematch&results=1">Bekijk de resultaten</a></b>
<?php
	
	}

	$poll = mysql_fetch_array (mysql_query ("SELECT pollid, title, voting, results, graph, resultsvotes FROM polls WHERE pollid='$whatpoll'"));
		
		if (($blocked == 'yes' | $voteip == 'no' | $votecookies == 'no' | isset ($_REQUEST['results']) | $poll['voting'] == 'no' | isset ($_REQUEST['option'])) && $poll['graph'] == 'yes' && $started == 'yes') {
		
			if (((isset ($_REQUEST['results']) && $poll['results'] == 'yes' && ($voteip != 'yes' | $votecookies != 'yes')) | !isset ($_REQUEST['results'])) && $started == 'yes') {
			
				$option = mysql_query ("SELECT options, votes, images, order_id FROM options WHERE pollid='$whatpoll' ORDER BY order_id ASC");
				$total = mysql_fetch_assoc (mysql_query ("SELECT SUM(votes) AS total FROM options WHERE pollid='$whatpoll'"));

?>
<table width="100%" border="0" cellspacing="0" cellpadding="2" class="border">
		<td height="25" colspan="2"><b><?= $poll['title']; ?></b></td>
	</tr>
	<?php 
	
	while ($optionrows = mysql_fetch_array ($option)) {
	
		@$percent = round (($optionrows['votes'] / $total['total']) * 100);
	
		if ($optionrows['images'] == 'random') {
					
			if ($handle = opendir ($dir2)) {
				  
				while (false !== ($file = readdir ($handle))) {
														
					if ($file != '.' && $file != '..') {
									
						$files[] = $file;
									
					}				
									
				}
								
				shuffle ($files);
							
			}
							
			$rand = rand (0, (count ($files) - 1));
							
			$optionrows['images'] = $files[$rand];
							
		}
	
?>
	<tr class="text">
		<td width="100%" height="25"><?= $optionrows['options']; ?>
        <br />
        <img src="<?= $dir2; ?>/<?= $optionrows['images']; ?>" width="<?= ($percent * $width) + 10; ?>" height="<?= $height; ?>" alt="<?= $optionrows['options']; ?>"><td width="100%"><b><td width="100%"><?= $percent; ?>%</b></td>
	</tr>
	<?php } ?>
	<tr class="text">
		<td height="25"><?php if ($poll['resultsvotes'] == "yes") { ?><b>Totaal&nbsp;<?= $total['total']; ?>&nbsp;stemmen</b>
<?php } if (isset ($_REQUEST['results'])) {?><br><?php } ?></td>
	</tr>
</table>
<img src="images/layout/marker.gif" alt="" style="margin-right:3px; margin-left:1px; vertical-align:middle"><b><a href="?id=manofthematch">Breng ook je stem uit!</a></b>
<?php

		}

	}

} else {

?>
<div align="center" class="text"><br /><b>Er zijn momenteel geen polls.<a href="admin/index.php" class="text">maak</a> een poll.</div>
<?php } if ($totalpolls > 0 && $poll['voting'] == 'no' && $poll['graph'] == 'no') { ?>
<div align="center" class="text">Helaas kunt u niet stemmen of de resultaten bekijken van deze poll</div>
<?php } if ($totalpolls > 0 && $poll['voting'] == 'yes' && $poll['graph'] == 'no' && isset ($_REQUEST['option'])) { ?>
<div align="center" class="text">Bedankt om te stemmen op de poll.</div>
<?php } if ($totalpolls > 0 && $poll['voting'] == 'yes' && $poll['graph'] == 'no' && ($voteip == 'no' | $votecookies == 'no') && !isset ($_REQUEST['option'])) { ?>
<div align="center" class="text">Sorry, je kunt niet stemmen op deze poll<b><?= $polls['title']; ?></b></div>
<?php } if ($totalpolls > 0 && $poll['results'] == 'no' && isset ($_REQUEST['results'])) { ?>
<div align="center" class="text">Sorry, je kunt niet de resultaten bekijken van deze poll<b><?= $polls['title']; ?></b></div>
<?php } ?>
 
Maak van

PHP:
"SELECT pollid, title, voting, results, graph FROM polls WHERE pollid='$whatpoll'"

eens

PHP:
"SELECT pollid, title, voting, results, graph FROM polls WHERE pollid='$whatpoll' ORDER BY results DESC"

EDIT: volgens mij zit de totale waarde van de votes bij jou niet in results, je moet even van ORDER BY results DESC maken: ORDER BY {column name total votes} DESC
 
Laatst bewerkt:
Maak van

PHP:
"SELECT pollid, title, voting, results, graph FROM polls WHERE pollid='$whatpoll'"

eens

PHP:
"SELECT pollid, title, voting, results, graph FROM polls WHERE pollid='$whatpoll' ORDER BY results DESC"

EDIT: volgens mij zit de totale waarde van de votes bij jou niet in results, je moet even van ORDER BY results DESC maken: ORDER BY {column name total votes} DESC

Dankjewel voor de snelle reactie.
Maar helaas het werkt niet
Dit heb ik nu staan op regel 1 t/m 11

PHP:
<?php

if ($totalpolls > 0) {

	if (!isset ($_REQUEST['option']) && !isset ($_REQUEST['results']) && $votecookies != 'no' && $voteip != 'no' && $blocked != 'yes' && $started == 'yes' && $expired == 'no' && $polls['voting'] == 'yes') {
	
		$poll = mysql_fetch_array (mysql_query ("SELECT pollid, title, voting, results, graph FROM polls WHERE pollid='$whatpoll' ORDER BY results DESC"));

		$option = mysql_query ("SELECT optionid, options, order_id FROM options WHERE pollid='$whatpoll' ORDER BY order_id ASC");
	
?>
 
Je kunt ons wel iets meer dan een half uur de tijd gunnen zeg.

Misschien kun je je database model even toelichten?
 
Je kunt ons wel iets meer dan een half uur de tijd gunnen zeg.

Misschien kun je je database model even toelichten?

Sorry.

sql.jpg
 
Dan zou ik van:

PHP:
"SELECT optionid, options, order_id FROM options WHERE pollid='$whatpoll' ORDER BY order_id ASC"

Het volgende maken:

PHP:
"SELECT optionid, options, order_id, FROM options WHERE pollid='$whatpoll' ORDER BY votes DESC"

Aangenomen dat in de kolom 'votes' het totale aantal stemmen voor de betreffende optie staat.
 
Dan zou ik van:

PHP:
"SELECT optionid, options, order_id FROM options WHERE pollid='$whatpoll' ORDER BY order_id ASC"

Het volgende maken:

PHP:
"SELECT optionid, options, order_id, FROM options WHERE pollid='$whatpoll' ORDER BY votes DESC"

Aangenomen dat in de kolom 'votes' het totale aantal stemmen voor de betreffende optie staat.

Helaas, maar werkt ook niet.

rij.jpg


Dit is hoe ik het net had staan, na uw post.

PHP:
<?php

if ($totalpolls > 0) {

	if (!isset ($_REQUEST['option']) && !isset ($_REQUEST['results']) && $votecookies != 'no' && $voteip != 'no' && $blocked != 'yes' && $started == 'yes' && $expired == 'no' && $polls['voting'] == 'yes') {
	
		$poll = mysql_fetch_array (mysql_query ("SELECT pollid, title, voting, results, graph FROM polls WHERE pollid='$whatpoll'"));

		$option = mysql_query ("SELECT optionid, options, order_id, FROM options WHERE pollid='$whatpoll' ORDER BY votes DESC");
	
?>
 
Oké, dan weet ik het ook even niet meer. Misschien kan een ander forumlid er nog eens naar kijken.
 
Oké, dan weet ik het ook even niet meer. Misschien kan een ander forumlid er nog eens naar kijken.

Moet je de rest van de pagina zien?

PHP:
<?php

if ($totalpolls > 0) {

	if (!isset ($_REQUEST['option']) && !isset ($_REQUEST['results']) && $votecookies != 'no' && $voteip != 'no' && $blocked != 'yes' && $started == 'yes' && $expired == 'no' && $polls['voting'] == 'yes') {
	
		$poll = mysql_fetch_array (mysql_query ("SELECT pollid, title, voting, results, graph FROM polls WHERE pollid='$whatpoll'"));

		$option = mysql_query ("SELECT optionid, options, order_id, FROM options WHERE pollid='$whatpoll' ORDER BY votes DESC");
	
?>
<form action="?id=manofthematch" method="post" name="frmPoll">
<table width="49%" border="0" cellspacing="0" cellpadding="2" class="border">
	<tr class="text">
		<td height="25" colspan="2" align="center"><b><?= $poll['title']; ?></b></td>
	</tr>
	<?php while ($optionrows = mysql_fetch_array ($option)) { ?>
	<tr class="text">
		<td width="10%" align="center" height="25"><input name="option" type="radio" value="<?= $optionrows['optionid']; ?>"<?php if ($optionrows['order_id'] == 1) { echo " CHECKED"; } ?>></td>
		<td width="90%"><?= $optionrows['options']; ?></td>
	</tr>
	<?php } ?>
	<tr>
		<td colspan="2" align="center" height="25"><input name="stage" type="hidden" value="2"/><input name="poll" type="hidden" value="<?= $poll['pollid']; ?>"><input name="btnVote" type="submit" value="Stemmen"/><br /><br />
		<?php if ($poll['results'] == 'yes' && $poll['graph'] == 'yes') { ?>
		<?php } ?></td>
	</tr>
</table>
</form>
<img src="images/layout/marker.gif" alt="" style="margin-right:3px; margin-left:1px; vertical-align:middle"><b><a href="?id=manofthematch&results=1">Bekijk de resultaten</a></b>
<?php
	
	}

	$poll = mysql_fetch_array (mysql_query ("SELECT pollid, title, voting, results, graph, resultsvotes FROM polls WHERE pollid='$whatpoll'"));
		
		if (($blocked == 'yes' | $voteip == 'no' | $votecookies == 'no' | isset ($_REQUEST['results']) | $poll['voting'] == 'no' | isset ($_REQUEST['option'])) && $poll['graph'] == 'yes' && $started == 'yes') {
		
			if (((isset ($_REQUEST['results']) && $poll['results'] == 'yes' && ($voteip != 'yes' | $votecookies != 'yes')) | !isset ($_REQUEST['results'])) && $started == 'yes') {
			
				$option = mysql_query ("SELECT options, votes, images, order_id FROM options WHERE pollid='$whatpoll' ORDER BY order_id ASC");
				$total = mysql_fetch_assoc (mysql_query ("SELECT SUM(votes) AS total FROM options WHERE pollid='$whatpoll'"));

?>
<table width="100%" border="0" cellspacing="0" cellpadding="2" class="border">
		<td height="25" colspan="2"><b><?= $poll['title']; ?></b></td>
	</tr>
	<?php 
	
	while ($optionrows = mysql_fetch_array ($option)) {
	
		@$percent = round (($optionrows['votes'] / $total['total']) * 100);
	
		if ($optionrows['images'] == 'random') {
					
			if ($handle = opendir ($dir2)) {
				  
				while (false !== ($file = readdir ($handle))) {
														
					if ($file != '.' && $file != '..') {
									
						$files[] = $file;
									
					}				
									
				}
								
				shuffle ($files);
							
			}
							
			$rand = rand (0, (count ($files) - 1));
							
			$optionrows['images'] = $files[$rand];
							
		}
	
?>
	<tr class="text">
		<td width="100%" height="25"><?= $optionrows['options']; ?>
        <br />
        <img src="<?= $dir2; ?>/<?= $optionrows['images']; ?>" width="<?= ($percent * $width) + 10; ?>" height="<?= $height; ?>" alt="<?= $optionrows['options']; ?>"><td width="100%"><b><td width="100%"><?= $percent; ?>%</b></td>
	</tr>
	<?php } ?>
	<tr class="text">
		<td height="25"><?php if ($poll['resultsvotes'] == "yes") { ?><b>Totaal&nbsp;<?= $total['total']; ?>&nbsp;stemmen</b>
<?php } if (isset ($_REQUEST['results'])) {?><br><?php } ?></td>
	</tr>
</table>
<img src="images/layout/marker.gif" alt="" style="margin-right:3px; margin-left:1px; vertical-align:middle"><b><a href="?id=manofthematch">Breng ook je stem uit!</a></b>
<?php

		}

	}

} else {

?>
<div align="center" class="text"><br /><b>Er zijn momenteel geen polls.<a href="admin/index.php" class="text">maak</a> een poll.</div>
<?php } if ($totalpolls > 0 && $poll['voting'] == 'no' && $poll['graph'] == 'no') { ?>
<div align="center" class="text">Helaas kunt u niet stemmen of de resultaten bekijken van deze poll</div>
<?php } if ($totalpolls > 0 && $poll['voting'] == 'yes' && $poll['graph'] == 'no' && isset ($_REQUEST['option'])) { ?>
<div align="center" class="text">Bedankt om te stemmen op de poll.</div>
<?php } if ($totalpolls > 0 && $poll['voting'] == 'yes' && $poll['graph'] == 'no' && ($voteip == 'no' | $votecookies == 'no') && !isset ($_REQUEST['option'])) { ?>
<div align="center" class="text">Sorry, je kunt niet stemmen op deze poll<b><?= $polls['title']; ?></b></div>
<?php } if ($totalpolls > 0 && $poll['results'] == 'no' && isset ($_REQUEST['results'])) { ?>
<div align="center" class="text">Sorry, je kunt niet de resultaten bekijken van deze poll<b><?= $polls['title']; ?></b></div>
<?php } ?>
 
Laatst bewerkt:
Ik ben niet zo bekend met de COUNT methode in MySQL.

Kun je eens een printscreen geven van de inhoud van die tabel. Dus bij 'Verkennen' en daar een screenshotje van maken.
 
Dus als ik het goed begrijp, heb je in Poll 1, 15 opties, waarvan 10 de meeste stemmen heeft.

Dan zou volgens mij de volgende query gewoon moeten werken.

PHP:
"SELECT optionid, votes FROM options WHERE poll_id = '" . $whatpoll . "' ORDER BY votes DESC"

Kun je eens de output laten zien die je dan krijgt?

Volgens mij ben ik namelijk niet helemaal helder aan het denken ;) Dus als iemand anders nog suggesties heeft...
 
Dus als ik het goed begrijp, heb je in Poll 1, 15 opties, waarvan 10 de meeste stemmen heeft.

Dan zou volgens mij de volgende query gewoon moeten werken.

PHP:
"SELECT optionid, votes FROM options WHERE poll_id = '" . $whatpoll . "' ORDER BY votes DESC"

Kun je eens de output laten zien die je dan krijgt?

Volgens mij ben ik namelijk niet helemaal helder aan het denken ;) Dus als iemand anders nog suggesties heeft...

Heb alles geprobeerd maar werkt niet.
Dit is de pagina waar het op zou "moeten" te komen staan.

eric%281%29.png

(Weer even de namen weggehaalt)
 
Laatst bewerkt:
Ik weet het niet hoor, ik vind het maar vreemd.

We hebben ook nog een pagina "top.php" die wordt geincluded op de polls.php pagina

PHP:
<?php

include ("config.php");

if (isset ($_REQUEST['poll'])) {

	$result = mysql_query ("SELECT pollid, title, starts, expires, vote, voting, results, graph, resultsvotes, ip, cookies FROM polls WHERE status='on' AND pollid='$_REQUEST[poll]'");
	
} else {

	$result = mysql_query ("SELECT pollid, title, starts, expires, vote, voting, results, graph, resultsvotes, ip, cookies FROM polls WHERE status='on' ORDER BY pollid DESC LIMIT 1");
	
}

$totalpolls = mysql_num_rows ($result);

if ($totalpolls > 0) {

	$polls = mysql_fetch_array ($result);
	
	$whatpoll = $polls['pollid'];
	$title = $polls['title'];
	
	// Calculate Poll Expiration
	list ($dayx, $monthx, $yearx) = explode ("/", $polls['expires']);
	$now = mktime (0, 0, 0, date ("m"), date ("d"), date ("Y"));
	$expire = mktime (0, 0, 0, $monthx, $dayx, $yearx);
	
	if ($expire <= $now) {
	
		$expired = "yes";
		
	} else {
	
		$expired = "no";
		
	}
	
	// Calculate Poll Start
	if ($expired == "no") {
	
		list ($days, $months, $years) = explode ("/", $polls['starts']);
		$starts = mktime (0, 0, 0, $months, $days, $years);
	
		if ($starts > $now) {
	
			$started = "no";
		
		} else {
	
			$started = "yes";
		
		}
		
	} else {
	
		$started = "no";
	
	}
	
	// Check if IP is blocked from voting
	$blockcheck = mysql_num_rows (mysql_query ("SELECT blockedid FROM blocked WHERE (polls LIKE '%$polls[title]%' OR polls LIKE '%all%') AND ip='$_SERVER[REMOTE_ADDR]'"));
	
	if ($blockcheck == 0) {
	
		$blocked = "no";
		
	} else {
	
		$blocked = "yes";
		
	}
	
	// Check if user has voted (IP)
	if ($polls['ip'] == "yes") {
	
		$check = mysql_query ("SELECT ipid, vote FROM ip WHERE title='$polls[title]' AND ip='$_SERVER[REMOTE_ADDR]'");
		$checkip = mysql_num_rows ($check);
		$ip = mysql_fetch_array ($check);
		
		if ($checkip == 0 | $ip['vote'] < time ()) {
		
			$voteip = "yes";
			
		} else {
		
			$voteip = "no";
			
		}
		
		if ($ip['vote'] <= time ()) {
		
			mysql_query ("DELETE FROM ip WHERE title='$polls[title]' AND ip='$_SERVER[REMOTE_ADDR]'");
			
		}
		
	} else {
	
		$voteip = "none";
		
	}
	
	// Check if user has voted (Cookie)
	if ($polls['cookies'] == "yes") {
		
		if (isset ($_COOKIE[$whatpoll])) {
		
			if ($_COOKIE[$whatpoll] == $title) {
		
				$votecookies = "no";
				
			} else {
			
				$votecookies = "yes";
			
			}
			
		} else {
		
			$votecookies = "yes";
			
		}
		
	} else {
	
		$votecookies = "none";
		
	} 
	
	if (isset ($_POST['stage'])) {

		$polls = mysql_fetch_array (mysql_query ("SELECT title, vote, ip, cookies FROM polls WHERE status='on' AND pollid='$_POST[poll]'"));
		$options = mysql_fetch_array (mysql_query ("SELECT optionid, options, votes FROM options WHERE pollid='$_POST[poll]' AND optionid='$_POST[option]'"));
		
		$title = $polls['title'];
		
		$nextvote = $polls['vote'] + time ();
		$votes = $options['votes'] + 1;
		
		if ($polls['ip'] == "yes" && $voteip != 'no') {
		
			$ip = mysql_fetch_array (mysql_query ("SELECT ipid FROM ip ORDER BY ipid DESC"));
			
			$ipid = $ip['ipid'] + 1;
		
			mysql_query ("INSERT INTO ip (ipid, title, ip, vote) VALUES ('$ipid', '$polls[title]', '$_SERVER[REMOTE_ADDR]', '$nextvote')");
			
		}
		
		if ($polls['cookies'] == "yes" && $votecookies != 'no') {
		
			setcookie ($whatpoll, $title, $nextvote);
			
		}
		
		if ($votecookies != 'no' && $voteip != 'no' && $blocked != 'yes' && $started == 'yes' && $expired == 'no') {
		
			mysql_query ("UPDATE options SET votes='$votes' WHERE optionid='$options[optionid]'");
			
		}
				
	}
	
}
	
?>
 
Ten eerste, de privacy die je probeert na te streven is nu nog steeds niet gewaarborgd. Met het plaatje van de resultaten zoals het er nu staat zijn de namen en de teams alsnog te achterhalen, de website is daarna ook makkelijk terug te vinden. Niet dat het naar mijn mening heel veel uitmaakt, maar toch.

Ten tweede zou de oplossing van Erik moeten werken, zou je het stukje code (inclusief query) dat de resultaten tabel genereert nog eens kunnen posten?
 
Laatst bewerkt:
Ten eerste, de privacy die je probeert na te streven is nu nog steeds niet gewaarborgd. Met het plaatje van de resultaten zoals het er nu staat zijn de namen en de teams alsnog te achterhalen, de website is daarna ook makkelijk terug te vinden. Niet dat het naar mijn mening heel veel uitmaakt, maar toch.

Ten tweede zou de oplossing van Erik moeten werken, zou je het stukje code (inclusief query) dat de resultaten tabel genereert nog eens kunnen posten?

Dit is de polls.php

PHP:
<?php

if ($totalpolls > 0) {

	if (!isset ($_REQUEST['option']) && !isset ($_REQUEST['results']) && $votecookies != 'no' && $voteip != 'no' && $blocked != 'yes' && $started == 'yes' && $expired == 'no' && $polls['voting'] == 'yes') {
	
		$poll = mysql_fetch_array (mysql_query ("SELECT pollid, title, voting, results, graph FROM polls WHERE pollid='$whatpoll'"));

		$option = mysql_query ("SELECT optionid, options, order_id FROM options WHERE pollid='$whatpoll' ORDER BY order_id ASC");
	
?>
<br /><form action="" method="post" name="frmPoll">
<table width="49%" border="0" cellspacing="0" cellpadding="2">
		<td height="25" colspan="2"><b><?= $poll['title']; ?></b></td>
	</tr>
	<?php while ($optionrows = mysql_fetch_array ($option)) { ?>
	<tr>
		<td width="10%" height="25"><input name="option" type="radio" value="<?= $optionrows['optionid']; ?>"<?php if ($optionrows['order_id'] == 1) { echo " CHECKED"; } ?>></td>
		<td width="90%"><?= $optionrows['options']; ?></td>
	</tr>
	<?php } ?>
	<tr>
		<td colspan="2" align="center" height="25"><input name="stage" type="hidden" value="2"/><input name="poll" type="hidden" value="<?= $poll['pollid']; ?>"><input name="btnVote" type="submit" value="Stemmen"/><br /><br />
		<?php if ($poll['results'] == 'yes' && $poll['graph'] == 'yes') { ?>
		<?php } ?></td>
	</tr>
</table>
</form>
<img src="images/layout/marker.gif" alt="" style="margin-right:3px; margin-left:1px; vertical-align:middle"><b><a href="?id=manofthematch&results=1">Bekijk de resultaten</a></b>
<?php
	
	}

	$poll = mysql_fetch_array (mysql_query ("SELECT pollid, title, voting, results, graph, resultsvotes FROM polls WHERE pollid='$whatpoll'"));
		
		if (($blocked == 'yes' | $voteip == 'no' | $votecookies == 'no' | isset ($_REQUEST['results']) | $poll['voting'] == 'no' | isset ($_REQUEST['option'])) && $poll['graph'] == 'yes' && $started == 'yes') {
		
			if (((isset ($_REQUEST['results']) && $poll['results'] == 'yes' && ($voteip != 'yes' | $votecookies != 'yes')) | !isset ($_REQUEST['results'])) && $started == 'yes') {
			
				$option = mysql_query ("SELECT options, votes, images, order_id FROM options WHERE pollid='$whatpoll' ORDER BY order_id ASC");
				$total = mysql_fetch_assoc (mysql_query ("SELECT SUM(votes) AS total FROM options WHERE pollid='$whatpoll'"));

?>
<table width="100%" border="0" cellspacing="0" cellpadding="2" class="border">
		<td height="25" colspan="2"><b><?= $poll['title']; ?></b></td>
	</tr>
	<?php 
	
	while ($optionrows = mysql_fetch_array ($option)) {
	
		@$percent = round (($optionrows['votes'] / $total['total']) * 100);
	
		if ($optionrows['images'] == 'random') {
					
			if ($handle = opendir ($dir2)) {
				  
				while (false !== ($file = readdir ($handle))) {
														
					if ($file != '.' && $file != '..') {
									
						$files[] = $file;
									
					}				
									
				}
								
				shuffle ($files);
							
			}
							
			$rand = rand (0, (count ($files) - 1));
							
			$optionrows['images'] = $files[$rand];
							
		}
	
?>
		<td width="100%" height="25"><?= $optionrows['options']; ?>
        <br />
        <img src="<?= $dir2; ?>/<?= $optionrows['images']; ?>" width="<?= ($percent * $width) + 10; ?>" height="<?= $height; ?>" alt="<?= $optionrows['options']; ?>"><td width="100%"><b><td width="100%"><?= $percent; ?>%</td></b>
	</tr>
	<?php } ?>
		<td height="25"><?php if ($poll['resultsvotes'] == "yes") { ?><b>Totaal&nbsp;<?= $total['total']; ?>&nbsp;stemmen</b>
<?php } if (isset ($_REQUEST['results'])) {?><br><?php } ?></td>
	</tr>
</table>
<img src="images/layout/marker.gif" alt="" style="margin-right:3px; margin-left:1px; vertical-align:middle"><b><a href="?id=manofthematch">Breng ook je stem uit!</a></b>
<?php

		}

	}

} else {

?>
<div align="center"><br /><b>Er zijn momenteel geen polls.<a href="admin/index.php">maak</a> een poll.</div>
<?php } if ($totalpolls > 0 && $poll['voting'] == 'no' && $poll['graph'] == 'no') { ?>
<div align="center">Helaas kunt u niet stemmen of de resultaten bekijken van deze poll</div>
<?php } if ($totalpolls > 0 && $poll['voting'] == 'yes' && $poll['graph'] == 'no' && isset ($_REQUEST['option'])) { ?>
<div align="center">Bedankt om te stemmen op de poll.</div>
<?php } if ($totalpolls > 0 && $poll['voting'] == 'yes' && $poll['graph'] == 'no' && ($voteip == 'no' | $votecookies == 'no') && !isset ($_REQUEST['option'])) { ?>
<div align="center">Sorry, je kunt niet stemmen op deze poll<b><?= $polls['title']; ?></b></div>
<?php } if ($totalpolls > 0 && $poll['results'] == 'no' && isset ($_REQUEST['results'])) { ?>
<div align="center">Sorry, je kunt niet de resultaten bekijken van deze poll<b><?= $polls['title']; ?></b></div>
<?php } ?>


Dit is de top.php

PHP:
<?php

include ("config.php");

if (isset ($_REQUEST['poll'])) {

	$result = mysql_query ("SELECT pollid, title, starts, expires, vote, voting, results, graph, resultsvotes, ip, cookies FROM polls WHERE status='on' AND pollid='$_REQUEST[poll]'");
	
} else {

	$result = mysql_query ("SELECT pollid, title, starts, expires, vote, voting, results, graph, resultsvotes, ip, cookies FROM polls WHERE status='on' ORDER BY pollid DESC LIMIT 1");
	
}

$totalpolls = mysql_num_rows ($result);

if ($totalpolls > 0) {

	$polls = mysql_fetch_array ($result);
	
	$whatpoll = $polls['pollid'];
	$title = $polls['title'];
	
	// Calculate Poll Expiration
	list ($dayx, $monthx, $yearx) = explode ("/", $polls['expires']);
	$now = mktime (0, 0, 0, date ("m"), date ("d"), date ("Y"));
	$expire = mktime (0, 0, 0, $monthx, $dayx, $yearx);
	
	if ($expire <= $now) {
	
		$expired = "yes";
		
	} else {
	
		$expired = "no";
		
	}
	
	// Calculate Poll Start
	if ($expired == "no") {
	
		list ($days, $months, $years) = explode ("/", $polls['starts']);
		$starts = mktime (0, 0, 0, $months, $days, $years);
	
		if ($starts > $now) {
	
			$started = "no";
		
		} else {
	
			$started = "yes";
		
		}
		
	} else {
	
		$started = "no";
	
	}
	
	// Check if IP is blocked from voting
	$blockcheck = mysql_num_rows (mysql_query ("SELECT blockedid FROM blocked WHERE (polls LIKE '%$polls[title]%' OR polls LIKE '%all%') AND ip='$_SERVER[REMOTE_ADDR]'"));
	
	if ($blockcheck == 0) {
	
		$blocked = "no";
		
	} else {
	
		$blocked = "yes";
		
	}
	
	// Check if user has voted (IP)
	if ($polls['ip'] == "yes") {
	
		$check = mysql_query ("SELECT ipid, vote FROM ip WHERE title='$polls[title]' AND ip='$_SERVER[REMOTE_ADDR]'");
		$checkip = mysql_num_rows ($check);
		$ip = mysql_fetch_array ($check);
		
		if ($checkip == 0 | $ip['vote'] < time ()) {
		
			$voteip = "yes";
			
		} else {
		
			$voteip = "no";
			
		}
		
		if ($ip['vote'] <= time ()) {
		
			mysql_query ("DELETE FROM ip WHERE title='$polls[title]' AND ip='$_SERVER[REMOTE_ADDR]'");
			
		}
		
	} else {
	
		$voteip = "none";
		
	}
	
	// Check if user has voted (Cookie)
	if ($polls['cookies'] == "yes") {
		
		if (isset ($_COOKIE[$whatpoll])) {
		
			if ($_COOKIE[$whatpoll] == $title) {
		
				$votecookies = "no";
				
			} else {
			
				$votecookies = "yes";
			
			}
			
		} else {
		
			$votecookies = "yes";
			
		}
		
	} else {
	
		$votecookies = "none";
		
	} 
	
	if (isset ($_POST['stage'])) {

		$polls = mysql_fetch_array (mysql_query ("SELECT title, vote, ip, cookies FROM polls WHERE status='on' AND pollid='$_POST[poll]'"));
		$options = mysql_fetch_array (mysql_query ("SELECT optionid, options, votes FROM options WHERE pollid='$_POST[poll]' AND optionid='$_POST[option]'"));
		
		$title = $polls['title'];
		
		$nextvote = $polls['vote'] + time ();
		$votes = $options['votes'] + 1;
		
		if ($polls['ip'] == "yes" && $voteip != 'no') {
		
			$ip = mysql_fetch_array (mysql_query ("SELECT ipid FROM ip ORDER BY ipid DESC"));
			
			$ipid = $ip['ipid'] + 1;
		
			mysql_query ("INSERT INTO ip (ipid, title, ip, vote) VALUES ('$ipid', '$polls[title]', '$_SERVER[REMOTE_ADDR]', '$nextvote')");
			
		}
		
		if ($polls['cookies'] == "yes" && $votecookies != 'no') {
		
			setcookie ($whatpoll, $title, $nextvote);
			
		}
		
		if ($votecookies != 'no' && $voteip != 'no' && $blocked != 'yes' && $started == 'yes' && $expired == 'no') {
		
			mysql_query ("UPDATE options SET votes='$votes' WHERE optionid='$options[optionid]'");
			
		}
				
	}
	
}
	
?>
 
PHP:
SELECT title, votes
FROM options o
JOIN polls p ON o.pollid = p.pollid
ORDER BY votes DESC;
Voer die query eens in phpMyAdmin in
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan