Foros del Web » Programando para Internet » PHP »

Ayuda Sistema de Puntuacion Por Favor

Estas en el tema de Ayuda Sistema de Puntuacion Por Favor en el foro de PHP en Foros del Web. Buenas Les comento, estoy realizando mi Web con DreamWeaver y PHP-MySQL. Ahora, tengo una Tabla de mi BD llamada Noticias, en la cual se encuentran ...
  #1 (permalink)  
Antiguo 25/05/2008, 15:51
Avatar de nicolyto77  
Fecha de Ingreso: marzo-2007
Ubicación: Buenos Aires
Mensajes: 782
Antigüedad: 17 años
Puntos: 12
Pregunta Ayuda Sistema de Puntuacion Por Favor

Buenas

Les comento, estoy realizando mi Web con DreamWeaver y PHP-MySQL.
Ahora, tengo una Tabla de mi BD llamada Noticias, en la cual se encuentran los campos: ID - Titulo - Mensaje - Puntuacion
Cuando hago el formulario de Envio de noticias, mando solo el campo Titulo y Mensaje, ya que el campo ID y Puntuacion los mando ocultos. (Puntuacion lo inicio en 0)

Luego, tengo el mi Index.php las Noticias enviadas, donde sale el Titulo y un pedazo del mensaje. Pero quisiera agregar un MiniFormulario de puntuacion, con 1 solo campo Select y el ID, en donde el Select contenga de 1 - 5. Y que SEGUN LA ID DE LA NOTICIA, al pulsar el boton, me sume la puntuacion.

(Si se puede, que saque un Promedio, mejor)

Me dan una mano por favor?

Saludos
__________________
CabaSoft Networks
  #2 (permalink)  
Antiguo 25/05/2008, 20:53
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Respuesta: Ayuda Sistema de Puntuacion Por Favor

Hola nicolyto77,

Para hacer el control del tipo select necesitas usar el tag de SELECT, revisa en el foro de HTML para que te orienten como hacerlo.

Posteriormente necesitaras hacer un UPDATE a tu base de datos una vez que envíen el formulario con el select y deberás de pasar el ID como campo oculto para que sepas diferenciar que articulo es.

Saludos.
  #3 (permalink)  
Antiguo 25/05/2008, 22:13
 
Fecha de Ingreso: enero-2008
Mensajes: 132
Antigüedad: 16 años, 2 meses
Puntos: 6
Respuesta: Ayuda Sistema de Puntuacion Por Favor

Código HTML:
<form action="puntuacion.php" method="POST">

<select name="puntuacion">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>

<input type="submit" value="Calificar">

</form> 
El Id lo puedes pasar por algun campo hidden

puntuacion.php:

Código PHP:

$id 
$_POST['id'];
$puntuacion $_POST['puntuacion'];

mysql_query("UPDATE Noticias SET puntuacion = $puntuacion WHERE ID = $id"); 
Suerte
  #4 (permalink)  
Antiguo 26/05/2008, 11:20
Avatar de nicolyto77  
Fecha de Ingreso: marzo-2007
Ubicación: Buenos Aires
Mensajes: 782
Antigüedad: 17 años
Puntos: 12
Respuesta: Ayuda Sistema de Puntuacion Por Favor

Muchas Gracias

Voy a probar a ver que tal sale

Saludos
__________________
CabaSoft Networks
  #5 (permalink)  
Antiguo 26/05/2008, 11:38
Avatar de nicolyto77  
Fecha de Ingreso: marzo-2007
Ubicación: Buenos Aires
Mensajes: 782
Antigüedad: 17 años
Puntos: 12
Exclamación Respuesta: Ayuda Sistema de Puntuacion Por Favor

Holas

Les agradezco mucho de todas maneras, pero el ultimo codigo no me funciono

Este es el Codigo que Dreamweaver hace para actualizar el registro, funciona perfecto, lo unico que yo quiero que no se actualice de esa forma... sino que se sumen.

Código PHP:
<?php
$currentPage 
$_SERVER["PHP_SELF"];

function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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;
}

$editFormAction $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) {
  
$editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset(
$_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  
$updateSQL sprintf("UPDATE post SET puntuacion=%s WHERE id=%s",
                       
GetSQLValueString($_POST['puntuacion'], "int"),
                       
GetSQLValueString($_POST['id'], "int"));

  
mysql_select_db($database_FS$FS);
  
$Result1 mysql_query($updateSQL$FS) or die(mysql_error());

  
$updateGoTo "index.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$updateGoTo .= (strpos($updateGoTo'?')) ? "&" "?";
    
$updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$updateGoTo));
}

$maxRows_rsUserFull 1;
$pageNum_rsUserFull 0;
if (isset(
$_GET['pageNum_rsUserFull'])) {
  
$pageNum_rsUserFull $_GET['pageNum_rsUserFull'];
}
$startRow_rsUserFull $pageNum_rsUserFull $maxRows_rsUserFull;

mysql_select_db($database_FS$FS);
$query_rsUserFull "SELECT * FROM registro";
$query_limit_rsUserFull sprintf("%s LIMIT %d, %d"$query_rsUserFull$startRow_rsUserFull$maxRows_rsUserFull);
$rsUserFull mysql_query($query_limit_rsUserFull$FS) or die(mysql_error());
$row_rsUserFull mysql_fetch_assoc($rsUserFull);

if (isset(
$_GET['totalRows_rsUserFull'])) {
  
$totalRows_rsUserFull $_GET['totalRows_rsUserFull'];
} else {
  
$all_rsUserFull mysql_query($query_rsUserFull);
  
$totalRows_rsUserFull mysql_num_rows($all_rsUserFull);
}
$totalPages_rsUserFull ceil($totalRows_rsUserFull/$maxRows_rsUserFull)-1;

$colname_rsUser "-1";
if (isset(
$_SESSION['MM_Username'])) {
  
$colname_rsUser = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_FS$FS);
$query_rsUser sprintf("SELECT * FROM registro WHERE username = '%s'"$colname_rsUser);
$rsUser mysql_query($query_rsUser$FS) or die(mysql_error());
$row_rsUser mysql_fetch_assoc($rsUser);
$totalRows_rsUser mysql_num_rows($rsUser);

$maxRows_rsPost 15;
$pageNum_rsPost 0;
if (isset(
$_GET['pageNum_rsPost'])) {
  
$pageNum_rsPost $_GET['pageNum_rsPost'];
}
$startRow_rsPost $pageNum_rsPost $maxRows_rsPost;

mysql_select_db($database_FS$FS);
$query_rsPost "SELECT * FROM post";
$query_limit_rsPost sprintf("%s LIMIT %d, %d"$query_rsPost$startRow_rsPost$maxRows_rsPost);
$rsPost mysql_query($query_limit_rsPost$FS) or die(mysql_error());
$row_rsPost mysql_fetch_assoc($rsPost);

if (isset(
$_GET['totalRows_rsPost'])) {
  
$totalRows_rsPost $_GET['totalRows_rsPost'];
} else {
  
$all_rsPost mysql_query($query_rsPost);
  
$totalRows_rsPost mysql_num_rows($all_rsPost);
}
$totalPages_rsPost ceil($totalRows_rsPost/$maxRows_rsPost)-1;

$queryString_rsPost "";
if (!empty(
$_SERVER['QUERY_STRING'])) {
  
$params explode("&"$_SERVER['QUERY_STRING']);
  
$newParams = array();
  foreach (
$params as $param) {
    if (
stristr($param"pageNum_rsPost") == false && 
        
stristr($param"totalRows_rsPost") == false) {
      
array_push($newParams$param);
    }
  }
  if (
count($newParams) != 0) {
    
$queryString_rsPost "&" htmlentities(implode("&"$newParams));
  }
}
$queryString_rsPost sprintf("&totalRows_rsPost=%d%s"$totalRows_rsPost$queryString_rsPost);
?>
Con ese formulario, cuando selecciono el 2 Por ejemplo, pulso el voton y el valor pasa a ser 2.. Pero si lo vuelvo a pulsar marcando el 3, me actualiza el campo a 3! y yo lo que necesito es que me sume el 2 que ya tenia, mas el 3... el nuevo

Espero su valiosa ayuda.

Gracias de antemano y Saludos
__________________
CabaSoft Networks
  #6 (permalink)  
Antiguo 26/05/2008, 11:51
Avatar de IMAC/  
Fecha de Ingreso: octubre-2005
Mensajes: 738
Antigüedad: 18 años, 5 meses
Puntos: 14
De acuerdo Respuesta: Ayuda Sistema de Puntuacion Por Favor

En la base de datos tienes que tener una tabla, pongamos "puntuacion" con los siguientes campos:
  • Puntuacion //contiene la suma total de votaciones
  • NumeroVotos //contiene el número de votos
  • Media //contiene la media de los votos, es decir, Puntuacion/NumeroVotos

Cada vez que alguien vote a un artículo como te han indicado los compañeros (con un id en una variable oculta y mediante un formulario que envie la puntuacion), tendrás que actualizar la base de datos del siguiente modo:

Actualizamos el campo puntuacion haciendo una select del valor actual que tiene este campo con nuestro id y le sumamos el valor de la votación que acaban de realizar.
Luego sumamos 1 al NumeroVotos.
Y luego sacamos la media haciendo Puntuacion/Media.

Supongo que sabrás SQL para realizar los updates anteriores.

Saludos.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 05:16.