Location: PHPKode > projects > Uniweb > Uniweb/votaselect.php
<?php
include "inc/config.inc";
conecta();
include "inc/sesion.inc";
include "inc/css.inc";
	$sql = "SELECT * FROM votacion ORDER BY id DESC LIMIT 1"; 
	if (($result = mysql_query($sql)) === FALSE){ 
	echo "MySQL Error: ".mysql_error()." 
	\n"; 
	die(); 
	}

	while ($myrow = mysql_fetch_array($result)){
		$title_vot = $myrow[title];
		$naslov = $myrow[id];
	};

// Tabla con opciones de votar
if ($HTTP_COOKIE_VARS["votar"] != $naslov) {
	$title_vot = stripslashes($title_vot);
	
	echo '
	<table border="0" bgcolor="'.$row_conf["conf_color_fuerte"].' " width=100% cellpadding="3" cellspacing="1">
	<form name="poll" method="post" action="votar.php">
	<tr bgcolor="'.$row_conf["conf_color_fuerte"].'"><td><span class="tit01"><b>'.$title_vot.'</b></span></td></tr>';
	

	// Opciones Votar
	$sql2 = "SELECT * FROM vota WHERE title='$naslov' ORDER BY id ASC"; 
	if (($result2 = mysql_query($sql2)) === FALSE){ 
	echo "MySQL Error: ".mysql_error()." 
	\n"; 
	die(); 
	}
	echo '
	<tr bgcolor="'.$row_conf['conf_color_claro'].'"><td>
	<table border="0" bgcolor="FFFFFF" width=100% cellpadding="1" cellspacing="0">
	';
	
	while ($myrow = mysql_fetch_array($result2)){
		$myrow[content] = stripslashes($myrow[content]);
		echo '
		<tr bgcolor="'.$row_conf['conf_color_claro'].'"><td><span class="texto01"><input ';
		//lo marcamos segun datos importados
		if ($id==$myrow[id])
		{
			echo " checked ";
		}
		
		echo 'type="radio" name="id" value="'.$myrow[id].'"><b>'.$myrow[content].'</b></font></td></tr>
		';
	};
	
	echo '
	<tr bgcolor="'.$row_conf['conf_color_claro'].'"><td><input type="submit" name="Encuesta" value="Votar" style="BORDER-RIGHT: #eeeeee 1px solid; BORDER-TOP: #eeeeee 1px solid; BACKGROUND: '.$row_conf['conf_color_boton'].'; FONT: 8pt verdana; BORDER-LEFT: #eeeeee 1px solid; COLOR: #ffffff; BORDER-BOTTOM: #eeeeee 1px solid"></td></tr>
	</form>
	</table></td></tr>
	</table>
	';
};

// tabla resultados
if ($HTTP_COOKIE_VARS["votar"] == $naslov) {
	echo '
	<table border="0" bgcolor="'.$row_conf["conf_color_fuerte"].'" width=100% cellpadding="3" cellspacing="1">
	';

	$sql = "SELECT * FROM votacion ORDER BY id desc LIMIT 1"; 
	if (($result = mysql_query($sql)) === FALSE){ 
	echo "MySQL Error: ".mysql_error()." 
	\n"; 
	die(); 
	}

	while ($myrow = mysql_fetch_array($result)){
		$myrow[title] = stripslashes($myrow[title]);
		echo '
		<tr bgcolor="'.$row_conf['conf_color_fuerte'].'"><td><span class="tit01"><b>'.$myrow[title].'</b></span></td></tr>
		';
	};

	// Total votos
	$sql2 = "SELECT number FROM vota WHERE title='$naslov' ORDER BY number DESC"; 
	if (($result2 = mysql_query($sql2)) === FALSE){ 
	echo "MySQL Error: ".mysql_error()." 
	\n"; 
	die(); 
	}
	
	$all = "0";
	
	while ($myrow = mysql_fetch_array($result2)){
		$all = $all + $myrow[number];
	};
	
	
	// Votos de cada opcion
	$sql2 = "SELECT * FROM vota WHERE title='$naslov' ORDER BY number DESC"; 
	if (($result2 = mysql_query($sql2)) === FALSE){ 
	echo "MySQL Error: ".mysql_error()." 
	\n"; 
	die(); 
	}
	echo '
	<tr bgcolor="'.$row_conf['conf_color_claro'].'"><td>
	<table border="0" bgcolor="FFFFFF" width=100% cellpadding="1" cellspacing="0">
	';
	
	while ($myrow = mysql_fetch_array($result2)){

		if ($all != "" OR "0") {
			$number = $myrow[number] / $all;
		};
	
		$number = substr($number, 0, 5);

		$number = $number * 100;
		$number2 = 100 - $number;
	
		$myrow[content] = stripslashes($myrow[content]);	
		echo '
		<tr bgcolor="'.$row_conf['conf_color_claro'].'"><td>
		<span class="texto01"><b>'.$myrow[content].'</b><br>
		<img src="imagenes/image1.gif" width="'.$number.'" height="10"><img src="imagenes/image2.gif" width="'.$number2.'" height="10"><br>
		'.$number.'% - '.$myrow[number].' votos</span>
		</td></tr>
		';
	};
	
	
	echo '
	
	<tr bgcolor="'.$row_conf['conf_color_claro'].'"><td><span class="texto01">Votos Totales: '.$all.'</span></td></tr>
	</table></td></tr>
	</table>
	';
};

?>
Return current item: Uniweb