Foros del Web » Programando para Internet » Javascript » Frameworks JS »

Alguna Idea de como hacer esto?

Estas en el tema de Alguna Idea de como hacer esto? en el foro de Frameworks JS en Foros del Web. Alguna Idea o Tutorial de como realizar esto? ejemplo 1 ejemplo 2 es un sistema de votos con mano arriba y mano abajo si alguien ...
  #1 (permalink)  
Antiguo 02/11/2009, 18:19
 
Fecha de Ingreso: octubre-2009
Mensajes: 61
Antigüedad: 14 años, 6 meses
Puntos: 0
Alguna Idea de como hacer esto?

Alguna Idea o Tutorial de como realizar esto?

ejemplo 1


ejemplo 2


es un sistema de votos con mano arriba y mano abajo

si alguien sabe le agradecere de antemano

Última edición por letal13; 02/11/2009 a las 20:06
  #2 (permalink)  
Antiguo 02/11/2009, 20:59
 
Fecha de Ingreso: octubre-2009
Mensajes: 97
Antigüedad: 14 años, 6 meses
Puntos: 4
Respuesta: Alguna Idea de como hacer esto?

Mas o menos yo pienso asi:

articulo.asp:
Código:
<%ruta="htt"&"p://"&request.servervariables("SERVER_NAME")&request.servervariables("SCRIPT_NAME")&"?votar=true"
if not request("votar")="true" then%>
---Aquí va el articulo o tema--
Califica el artículo:<br>
<img src="no.gif" border=0 onclick="votar('no')" style=cursor:hand> <img src="si.gif" border=0 onclick="votar('si')" style=cursor:hand>
<script>function votar(voto){
var ajax=new ActiveXObject("msxml2.XMLHTTP");
ajax.open("GET","<%=ruta%>&id_articulo=aquivaeliddelarticulo&voto="+voto,false);
ajax.send();
alert(ajax.ResponseText)}</script>
<%else
set rs=server.createobject("adodb.connection")
rs.open "provider=microsoft.jet.oledb.4.0;data source="&server.mappath("aqui va la base de datos")
set seleccion=rs.execute("select * from votos where id_articulo="&request("id_articulo"))
if request("voto")="si" then
rs.execute("update votos set si='"&seleccion("si")+1&"' where id_articulo="&request("id_articulo"))
elseif request("voto")="no" then
rs.execute("update votos set no='"&seleccion("no")+1&"'' where id_articulo="&request("id_articulo"))
response.write "Gracias por votar."
end if%>
Nota: Tu bd deberia llevar las siguientes columnas: id_articulo, si, no
  #3 (permalink)  
Antiguo 02/11/2009, 21:06
 
Fecha de Ingreso: octubre-2009
Mensajes: 61
Antigüedad: 14 años, 6 meses
Puntos: 0
Respuesta: Alguna Idea de como hacer esto?

gracias amigo por la respuesta pero mas aya no e entendido muy bien tu codigo si no fuera mucha molestia podrias explicarlo
  #4 (permalink)  
Antiguo 02/11/2009, 21:29
 
Fecha de Ingreso: octubre-2009
Mensajes: 97
Antigüedad: 14 años, 6 meses
Puntos: 4
Respuesta: Alguna Idea de como hacer esto?

Tienes una base de datos con las siguientes columnas: id_articulo, si, no
En "id_articulo" va el identificador del tema (p.j: numeros y letras al azar)
En "si" va el número de personas que votaron por la opcion si
En "no" es igual
La página articulo.asp muestra tu tema o articulo. Al hacer clic en si se crea el objeto ajax y se llama a la misma página (articulo.asp) pero con "votar=true" y con el voto si. La página lee el voto actual de la bd y le suma 1 y aparece: "Gracias por votar." luego aparece una alerta diciendo eso.
Cuando haces clic en no es exactamente lo mismo, pero en la columna no.

Para que todo esto funcione, debes hacer una lista de id's de todos tus temas y en "si" ponerle 0 y en "no" igual.
  #5 (permalink)  
Antiguo 03/11/2009, 12:07
 
Fecha de Ingreso: octubre-2009
Mensajes: 61
Antigüedad: 14 años, 6 meses
Puntos: 0
Respuesta: Alguna Idea de como hacer esto?

caray man gracias por la explicacion pero me serviria mejor si estuviera en php ya q es lo q ahora estoy usando
  #6 (permalink)  
Antiguo 03/11/2009, 13:18
 
Fecha de Ingreso: octubre-2009
Mensajes: 97
Antigüedad: 14 años, 6 meses
Puntos: 4
Respuesta: Alguna Idea de como hacer esto?

A tus ordenes:
Código:
<? $ruta="htt"."p://".$_SERVER["SERVER_NAME"].$_SERVER["SCRIPT_NAME"]."?votar=true";
if (!${"votar"}=="true")
{
?>
---Aquí va el articulo o tema--
Califica el artículo:<br>
<img src="no.gif" border=0 onclick="votar('no')" style=cursor:hand> <img src="si.gif" border=0 onclick="votar('si')" style=cursor:hand>
<script>function votar(voto){
var ajax=new ActiveXObject("msxml2.XMLHTTP");
ajax.open("GET","<?   echo $ruta; ?>&id_articulo=aquivaeliddelarticulo&voto="+voto,false);
ajax.send();
alert(ajax.ResponseText)}</script>
<? }
  else
{

// $rs is of type "adodb.connection"

  $rs=mysql_connect("localhost","","");
mysql_select_db("",$rs);
$seleccion=$seleccion_query=mysql_query(("select * from votos where id_articulo=".${"id_articulo"}),$rs);  
$seleccion=mysql_fetch_array($seleccion_query);
  if (${"voto"}=="si")
  {

    mysql_query(("update votos set si='".$seleccion["si"]+1."' where id_articulo=".${"id_articulo"}),$rs);  }
    else
  if (${"voto"}=="no")
  {

    mysql_query(("update votos set no='".$seleccion["no"]+1."'' where id_articulo=".${"id_articulo"}),$rs);    print "Gracias por votar.";
  } }
?>
  #7 (permalink)  
Antiguo 06/11/2009, 23:56
 
Fecha de Ingreso: octubre-2009
Mensajes: 61
Antigüedad: 14 años, 6 meses
Puntos: 0
Respuesta: Alguna Idea de como hacer esto?

hermano muchas gracias por toda la ayuda pero aun no puedo echar a andar el codigo.

aqui los codigos de las paginas

votes.php
Código HTML:
<!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>Documento sin título</title>
<script type="text/javascript">
function creaAjax(){
         var objetoAjax=false;
         try {
          /*Para navegadores distintos a internet explorer*/
          objetoAjax = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
          try {
                   /*Para explorer*/
                   objetoAjax = new ActiveXObject("Microsoft.XMLHTTP");
                   }
                   catch (E) {
                   objetoAjax = false;
          }
         }

         if (!objetoAjax && typeof XMLHttpRequest!='undefined') {
          objetoAjax = new XMLHttpRequest();
         }
         return objetoAjax;
}
function votar(voto){
	var ajax=new ActiveXObject("msxml2.XMLHTTP");
	ajax.open("GET","vote.php?votar=true&id=1&voto="+voto,false);
	ajax.send();
	alert(ajax.ResponseText);
}
</script>
</head>

<body>
<img src="si.gif" onclick="votar('si')" style="cursor:hand">
</body>
</html> 
vote.php
Código PHP:
<?php
require("../db_config.php");
$link=conectarse();
$voto $_GET['voto'];
$sql mysql_query("SELECT * FROM news WHERE id_new='1'",$link);
$sqld1 mysql_fetch_array($sql);
if(
$voto == "si"){
    
$votos = $$sqld1[puntos];
    
$votosd1 $votos+1;
    
mysql_query("UPDATE news SET puntos='$votosd1' WHERE id_new='1'",$link);
    echo 
"Su Voto Fue Agregado";
}
?>

Última edición por letal13; 07/11/2009 a las 00:32
  #8 (permalink)  
Antiguo 07/11/2009, 12:14
 
Fecha de Ingreso: octubre-2009
Mensajes: 97
Antigüedad: 14 años, 6 meses
Puntos: 4
Respuesta: Alguna Idea de como hacer esto?

¿Te sale error o que?
  #9 (permalink)  
Antiguo 07/11/2009, 12:28
 
Fecha de Ingreso: octubre-2009
Mensajes: 61
Antigüedad: 14 años, 6 meses
Puntos: 0
Respuesta: Alguna Idea de como hacer esto?

ok ya e echo andar el codigo con la siguientes instrucciones

votes.php
Código PHP:
<!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>Documento sin título</title>
<
script type="text/javascript">
function 
objetoAjax(){
 var 
xmlhttp=false;
 try {
 
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (
e) {
 try {
 
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 } catch (
E) {
 
xmlhttp false;
 }
 }
 if (!
xmlhttp && typeof XMLHttpRequest!='undefined') {
   
xmlhttp = new XMLHttpRequest();
   }
   return 
xmlhttp;
}

function 
votar(voto){
    
ajax=objetoAjax();
    
ajax.open("GET","vote.php?voto="+voto);
    
ajax.send();
}
</script>
</head>

<body>
<img src="si.gif" border="0" onclick="javascript:votar('si')">
</body>
</html> 
vote.php
Código PHP:
<?php
require("../db_config.php");
$link=conectarse();
$voto $_GET['voto'];
$sql mysql_query("SELECT * FROM news WHERE id_new='1'",$link);
$sqld1 mysql_fetch_array($sql);
if(
$voto == "si"){
    
$votos $sqld1[puntos];
    
$votosd1 $votos+1;
    
mysql_query("UPDATE news SET puntos='$votosd1' WHERE id_new='1'",$link);
}
?>
ahora lo q quiero saber es como le puedo poder que al darle clic en si o en no aparesca un mensaje diciendo que el voto se a agregado con exito

Última edición por letal13; 07/11/2009 a las 23:39
  #10 (permalink)  
Antiguo 08/11/2009, 18:14
 
Fecha de Ingreso: octubre-2009
Mensajes: 97
Antigüedad: 14 años, 6 meses
Puntos: 4
Respuesta: Alguna Idea de como hacer esto?

En votes.php pon esto:

Código:
<!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>Documento sin título</title> 
<script type="text/javascript"> 
function objetoAjax(){ 
 var xmlhttp=false; 
 try { 
 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
 } catch (e) { 
 try { 
 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
 } catch (E) { 
 xmlhttp = false; 
 } 
 } 
 if (!xmlhttp && typeof XMLHttpRequest!='undefined') { 
   xmlhttp = new XMLHttpRequest(); 
   } 
   return xmlhttp; 
} 

function votar(voto){ 
    ajax=objetoAjax(); 
    ajax.open("GET","vote.php?voto="+voto); 
    ajax.send(); 
    alert("Se ha agregado su voto. Gracias.");
} 
</script> 
</head> 

<body> 
<img src="si.gif" border="0" onclick="javascript:votar('si')"> 
</body> 
</html>
  #11 (permalink)  
Antiguo 08/11/2009, 23:45
 
Fecha de Ingreso: octubre-2009
Mensajes: 61
Antigüedad: 14 años, 6 meses
Puntos: 0
Respuesta: Alguna Idea de como hacer esto?

pero no quiero una ventana de alerta hermano lo q quiero es un mensaje q aparezca creo q es llamando a un div o algo asi pero no c como hacerlo
  #12 (permalink)  
Antiguo 09/11/2009, 09:06
 
Fecha de Ingreso: octubre-2009
Mensajes: 97
Antigüedad: 14 años, 6 meses
Puntos: 4
Respuesta: Alguna Idea de como hacer esto?

Trata con ésta código:
votes.php:
Código:
<html>
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Documento sin título</title> 
<script type="text/javascript"> 
function objetoAjax(){ 
 var xmlhttp=false; 
 try { 
 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
 } catch (e) { 
 try { 
 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
 } catch (E) { 
 xmlhttp = false; 
 } 
 } 
 if (!xmlhttp && typeof XMLHttpRequest!='undefined') { 
   xmlhttp = new XMLHttpRequest(); 
   } 
   return xmlhttp; 
} 

function votar(voto){ 
    ajax=objetoAjax(); 
    ajax.open("GET","vote.php?voto="+voto); 
    ajax.send(); 
    document.getElementById('area').innerHTML='Gracias.<br>Se ha agregado su voto.';
} 
</script> 
</head> 

<body> 
<img src="si.gif" border="0" onclick="javascript:votar('si')"> 
<div id=area></div>
</body> 
</html>
  #13 (permalink)  
Antiguo 09/11/2009, 13:17
 
Fecha de Ingreso: octubre-2009
Mensajes: 61
Antigüedad: 14 años, 6 meses
Puntos: 0
Respuesta: Alguna Idea de como hacer esto?

Gracias Hermano ahora funciona pero lo q estoy notando es q si ocurre algun error con la consulta por ejemplo como mostrar un mensaje de error si falla la consulta...

ya lo e logrado muchas gracias hermano

Última edición por letal13; 09/11/2009 a las 14:43
  #14 (permalink)  
Antiguo 10/11/2009, 20:37
Avatar de a83
a83
 
Fecha de Ingreso: noviembre-2005
Ubicación: Santiago de chile
Mensajes: 637
Antigüedad: 18 años, 5 meses
Puntos: 1
Respuesta: Alguna Idea de como hacer esto?

consulta letal13 como funciona la opcion de no solo aparece el si esta interesante esto

saludos



Cita:
Iniciado por letal13 Ver Mensaje
Gracias Hermano ahora funciona pero lo q estoy notando es q si ocurre algun error con la consulta por ejemplo como mostrar un mensaje de error si falla la consulta...

ya lo e logrado muchas gracias hermano
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




La zona horaria es GMT -6. Ahora son las 21:31.