Foros del Web » Programando para Internet » PHP »

Error al imprimir datos, ¿alguien puede revisarlo?

Estas en el tema de Error al imprimir datos, ¿alguien puede revisarlo? en el foro de PHP en Foros del Web. Hola a todos, vereis, llevo tiempo (demasiado) intentando sacar este código adelante, tengo un pequeño fallo con los botones, que no consigo detectar. El sistema ...
  #1 (permalink)  
Antiguo 12/12/2011, 18:52
Avatar de TheScript  
Fecha de Ingreso: septiembre-2011
Ubicación: Spain
Mensajes: 164
Antigüedad: 12 años, 7 meses
Puntos: 30
Error al imprimir datos, ¿alguien puede revisarlo?

Hola a todos, vereis, llevo tiempo (demasiado) intentando sacar este código adelante, tengo un pequeño fallo con los botones, que no consigo detectar. El sistema es sencillo, mis usuarios tienen un sistema de amistades, cuando ellos pulsan para ver la lista de miembros, cada miembro sale con su foto, su nombre y un boton que da la opcion de agregar como amigo, al pulsarlo se mete en la base de datos como peticion de amistad realizada, y seguidamente ese boton se intercambia por otro que dice 'cancelar'. El tema es que solo con ajax me funciona, pero al meterle el php con la funcion de imprimir a los usuarios y guardar los datos, el boton hace su funcion pero el efecto en ajax deja de hacerlo...( y en ningun momento modifico el codigo ajax...)

Aqui el código completo:

Código PHP:

<?php
include "lib/conectar.php";

?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"><head>
 <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<meta content="en-us" http-equiv="Content-Language">
 <title>Tutorials</title>
    
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
  
<script type="text/javascript">
$(function() {
$(".follow").click(function(){
var element = $(this);
var I = element.attr("id");
var info = 'id=' + I;
$("#loading").html('<img src="loader.gif" align="absmiddle">&nbsp;loading...');

 $.ajax({
   type: "POST",
   url: "lib/follow.php",
   data: info,
   success: function(){
   
 $("#loading").ajaxComplete(function()
     {
         
   }).slideUp();
 
     $('#follow'+I).fadeOut(200).hide();
    $('#remove'+I).fadeIn(200).show();
   }
 });

return false;

});

});
</script>

<script type="text/javascript">
$(function() {
$(".remove").click(function(){
var element = $(this);
var I = element.attr("id");

var info = 'id=' + I;
$("#loading").html('<img src="loader.gif" align="absmiddle">&nbsp;loading...');

 $.ajax({
   type: "POST",
   url: "lib/remove.php",
   data: info,
   success: function(){
   $("#loading").ajaxComplete(function()
     {}).slideUp();
   
    $('#remove'+I).fadeOut(200).hide();
    $('#follow'+I).fadeIn(200).show();
   }
 });

return false;

});

});
</script>


</head>
  
  <body>  
  
   <?php 
  $conn 
conectar();
  
$i 0
  
$sql1 "SELECT * FROM usuarios U WHERE NOT exists (SELECT * FROM amistades A where A.id_usuario_a = U.id_usuario and A.id_usuario_b = '1' or  A.id_usuario_a =                 '1' and A.id_usuario_b = U.id_usuario or U.id_usuario='1')";
 
  
$resultado1 mysql_query($sql1$conn) or die(mysql_error());
    
?>
  
       <table align="center">
          <tbody>
            <tr>            
            <td width='455' valign="top">
                <h3>Click <span style="color:#006699">Follow</span> and <span style="color:#006699">remove</span> Buttons</h3>
               </td></tr>
              <tr>            
            <td width='455' valign="top">
                <div id="loading"></div>
              </td></tr>
              <tr><td>
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
                  <?php while($row1 mysql_fetch_assoc($resultado1)){ ?>
<tr class="record">


<?php
$foto_perfil 
"imagenes/'".$row1['id_usuario']."'/'".$row1['id_usuario']."'.jpg";
        
$default_perfil "imagenes/0/perfil.jpg";
        if (
file_exists($foto_perfil)) {?>
        
        <td width="51"><img src="<?php echo $foto_perfil?>" width="50" height="50"/></td>
        
       <?php
        
} else { 
        
?>
        <td width="51"><img src="<?php echo $default_perfil?>" width="50" height="50"/></td>
        
    <?php 
    
}?>    

<td width="7" align="right" ></td>
<td width="376" class="content">
<strong ><a href="http://twitter.com/9lessons" style="color:#d02b55;"><?php echo $row1['nombre']; ?></a></strong>

Srinivas Tamada. <br />

<div id="follow1"><a href="#" class="follow" id="<?php $row1['id_usuario']?>"><span class="follow_b"> Follow </span></a></div>
<div id="remove1" style="display:none"><span class="youfollowing_b"> You Following </span><a href="#" class="remove" id="<?php $row1['id_usuario']?>"><span class="remove_b"> remove </span></a></div>

</td>
 </tr> 
 <?php $i++; 
    }
?>
</table>              
 </div>
</td></tr>
</tbody>
</table>
</div>
</body></html>
Si alguien puede echarle un vistazo al codigo lo agradeceria enormemente...

Aqui dejo solo la parte de php:

Código PHP:

<?php 
  $conn 
conectar();
  
$i 0
  
$sql1 "SELECT * FROM usuarios U WHERE NOT exists (SELECT * FROM amistades A where A.id_usuario_a = U.id_usuario and A.id_usuario_b = '1' or  A.id_usuario_a =                 '1' and A.id_usuario_b = U.id_usuario or U.id_usuario='1')";
 
  
$resultado1 mysql_query($sql1$conn) or die(mysql_error());
    
?>
  
       <table align="center">
          <tbody>
            <tr>            
            <td width='455' valign="top">
                <h3>Click <span style="color:#006699">Follow</span> and <span style="color:#006699">remove</span> Buttons</h3>
               </td></tr>
              <tr>            
            <td width='455' valign="top">
                <div id="loading"></div>
              </td></tr>
              <tr><td>
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
                  <?php while($row1 mysql_fetch_assoc($resultado1)){ ?>
<tr class="record">


<?php
$foto_perfil 
"imagenes/'".$row1['id_usuario']."'/'".$row1['id_usuario']."'.jpg";
        
$default_perfil "imagenes/0/perfil.jpg";
        if (
file_exists($foto_perfil)) {?>
        
        <td width="51"><img src="<?php echo $foto_perfil?>" width="50" height="50"/></td>
        
       <?php
        
} else { 
        
?>
        <td width="51"><img src="<?php echo $default_perfil?>" width="50" height="50"/></td>
        
    <?php 
    
}?>    

<td width="7" align="right" ></td>
<td width="376" class="content">
<strong ><a href="http://twitter.com/9lessons" style="color:#d02b55;"><?php echo $row1['nombre']; ?></a></strong>

Srinivas Tamada. <br />

<div id="follow1"><a href="#" class="follow" id="<?php $row1['id_usuario']?>"><span class="follow_b"> Follow </span></a></div>
<div id="remove1" style="display:none"><span class="youfollowing_b"> You Following </span><a href="#" class="remove" id="<?php $row1['id_usuario']?>"><span class="remove_b"> remove </span></a></div>

</td>
 </tr> 
 <?php $i++; 
    }
?>
</table>              
 </div>
</td></tr>
</tbody>
</table>
</div>
  #2 (permalink)  
Antiguo 12/12/2011, 18:58
Avatar de memoadian
Colaborador
 
Fecha de Ingreso: junio-2009
Ubicación: <?php echo 'México'?>
Mensajes: 3.696
Antigüedad: 14 años, 9 meses
Puntos: 641
Respuesta: Error al imprimir datos, ¿alguien puede revisarlo?

creo que este tema va en AJAX :/
  #3 (permalink)  
Antiguo 12/12/2011, 19:00
Avatar de TheScript  
Fecha de Ingreso: septiembre-2011
Ubicación: Spain
Mensajes: 164
Antigüedad: 12 años, 7 meses
Puntos: 30
Respuesta: Error al imprimir datos, ¿alguien puede revisarlo?

Bueno... yo creo que el problema viene de php.. pero quizas tengas razón, postearé allí a ver que tal...

Gracias memoadian.

Etiquetas: html, mysql, sql, usuarios
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 11:31.