Ir para conteúdo
Fórum Script Brasil
  • 0

Votação de Musicas


gallobr

Pergunta

Olá tenho um banco de dados com o nome de login, tabela top10 com 30 musicas.

A pagina top10.php é mostrada dessa forma:

<?php require_once('Connections/radioxtudo.php'); ?>

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {

case "text":

$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

break;

case "long":

case "int":

$theValue = ($theValue != "") ? intval($theValue) : "NULL";

break;

case "double":

$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";

break;

case "date":

$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

break;

case "defined":

$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

break;

}

return $theValue;

}

}

mysql_select_db($database_radioxtudo, $radioxtudo);

$query_Recordset1 = "SELECT * FROM top10";

$Recordset1 = mysql_query($query_Recordset1, $radioxtudo) or die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

$totalRows_Recordset1 = mysql_num_rows($Recordset1);

mysql_select_db($database_radioxtudo, $radioxtudo);

$query_Recordset2 = "SELECT Musica FROM top10";

$Recordset2 = mysql_query($query_Recordset2, $radioxtudo) or die(mysql_error());

$row_Recordset2 = mysql_fetch_assoc($Recordset2);

$totalRows_Recordset2 = mysql_num_rows($Recordset2);

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>..:: Radio X-TuDo ::.. | Matando sua fome de diversão!!!</title>

<style type="text/css">

<!--

body,td,th {

font-family: Tahoma;

font-size: 10pt;

color: #FFFFFF;

}

body {

background:fixed;

background-image: url(images/fundo_meio.gif);

}

a {

font-family: Tahoma;

font-size: 10pt;

color: #FFFFFF;

}

a:link {

text-decoration: none;

}

a:visited {

text-decoration: none;

color: #FFFFFF;

}

a:hover {

text-decoration: underline;

color: #FF0000;

}

a:active {

text-decoration: none;

color: #FFFFFF;

}

-->

</style></head>

<body>

<table width="100%" border="0">

<tr>

<td width="95%"><img src="images/painel_escolha_melhor.png" width="306" height="68" /></td>

<td width="5%"><div align="center"><a href="java script:java script:window.history.go(-1)" target="I1"><img src="images/voltar.png" alt="" width="45" height="30" border="0" /></a></div></td>

</tr>

</table>

<hr />

<form id="form1" name="form1" method="POST">

<label>

<select name="musicas" id="musicas" title="Escolha sua música!!">

<?php

do {

?>

<option value="<?php echo $row_Recordset2['Musica']?>"<?php if (!(strcmp($row_Recordset2['Musica'], "+1"))) {echo "selected=\"selected\"";} ?>><?php echo $row_Recordset2['Musica']?></option>

<?php

} while ($row_Recordset2 = mysql_fetch_assoc($Recordset2));

$rows = mysql_num_rows($Recordset2);

if($rows > 0) {

mysql_data_seek($Recordset2, 0);

$row_Recordset2 = mysql_fetch_assoc($Recordset2);

}

?>

</select>

</label>

<label>

<input type=submit" name="votar" id="votar" value="Votar" />

</label>

</form>

<hr />

<table width="100%" border="0">

<tr>

<td colspan="3"><div align="center"><strong>Resultado Atual!!</strong></div></td>

</tr>

<tr>

<td width="33%"><strong>Música</strong></td>

<td width="34%"><strong>Artista</strong></td>

<td width="33%"><strong>Votos</strong></td>

</tr>

<?php do { ?>

<tr>

<td width="33%"><?php echo $row_Recordset1['Musica]; ?></td>

<td width="34%"><?php echo $row_Recordset1['Artista']; ?></td>

<td width=33%"><?php echo $row_Recordset1['Voto]; ?></td>

</tr>

<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>

</table>

</body>

</html>

<?php

mysql_free_result($Recordset1);

mysql_free_result($Recordset2);

?>

Na listbox o visitante escolhe a musica e clica em votar para que TEORICAMENTE some +1 la na coluna voto na tabela top10. Porém eu não estou conseguindo fazer isso, alguém saberia me ajudar por favor?

Gallo

Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

  • 0

Seria mais fácil você criar uma coluna votos na tabela música.

Mas já que você quer assim você pode simplesmente checar se o cara votou e incrementar 1 ao valor da coluna votos usando SELETCT >UPDATE

<?php
// resgata form
$musicas = @$_POST['musicas']; //TODO tratar dados

// verifica se form foi preenchido
if(isset($musicas) and strlen($musicas) >= 3)
{

// resgata quantidade de votos a partir do bd
$query_Recordset3 = "SELECT votos FROM top10 WHERE='".$musica."'";
$Recordset3 = mysql_query($query_Recordset3, $radioxtudo) or die(mysql_error());
$row_Recordset3 = mysql_fetch_assoc($Recordset3);
$nvotos = $row_Recordset3['votos'];

// verifica se valor do bd é positivo
if($nvotos >= 0)
{

// incrementa um voto a mais
$nvotos = $nvotos+1;
$sql ="UPDATE top10 SET votos='".$nvotos."' WHERE musica='".$musica."'";
mysql_query($sql) or die(trigger_error(mysql_error()));
}
}
?>

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      652k
×
×
  • Criar Novo...