Ver Mensaje Individual
  #4 (permalink)  
Antiguo 04/11/2011, 12:26
tomirammstein
 
Fecha de Ingreso: septiembre-2011
Mensajes: 52
Antigüedad: 12 años, 7 meses
Puntos: 0
Exclamación Respuesta: Problema con recoleccion de datos

Cita:
Iniciado por s00rk Ver Mensaje
Es normal porque lo que haces es repetir o mas bn escribir varias veces la misma funcion likes() por cada fila obtenida por tu consulta deverias mejor ponerlo algo asi:
Código PHP:
Ver original
  1. <script language="javascript">
  2.         function likes(mensaje){
  3.         alert(mensaje);
  4.         }
  5. </script>
  6. <?php
  7. include('dbs.php'); //CONEXION A LA BASE DE DATOS
  8.  
  9. $nick=$_GET['nick'];
  10. $resultados = mysql_query("SELECT * FROM comentarios WHERE usuario = '$nick'");
  11. while($rowCom=mysql_fetch_array($resultados))
  12. {
  13.     $rowComID=$rowCom['id_comentario'];
  14.     ?>
  15.     <span><?=$rowCom['usuario']?></span> dijo
  16.       <p><?=$rowCom['comentario']?></p>
  17.       <p onclick="likes(<?=$rowComID?>)"><?=$rowComID?></p>
  18.     <?
  19. }
  20. ?>

<script language="javascript">
function ajaxObject(){
var xmlhttp=false;
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch(x){
try{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(X){
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!="undefined") {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
function likes(mensaje){
Ajax=ajaxObject();
Ajax.open("GET", "procesar_like.php?id_Comentario="+mensaje);
Ajax.onreadystatechange=function() {
if (Ajax.readyState==4) {
alert(Ajax.responseText);
}
}
Ajax.send(null)
}
</script>
<?php
include('dbs.php'); //CONEXION A LA BASE DE DATOS

$nick=$_GET['nick'];
$resultados = mysql_query("SELECT * FROM comentarios WHERE usuario = '$nick'");
while($rowCom=mysql_fetch_array($resultados))
{
$rowComID=$rowCom['id_comentario'];
?>
<span><?=$rowCom['usuario']?></span> dijo
<p><?=$rowCom['comentario']?></p>
<p onclick="likes(<?=$rowComID?>)"><?=$rowComID?></p>
<?
}
?>


Pero con Ajax no me funciona amigo :S

Mucas gracias a todos los que comentan