Aquí el sistema de los botones en ajax, sin php ni nada.
Código HTML:
<!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"> loading...'); </script>
Código HTML:
<strong ><a href="http://twitter.com/asdasd" style="color:#d02b55;">usuario 1</a></strong> usuario 1. <br /> <div id="follow1"><a href="#" class="follow" id="1"><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="1"><span class="remove_b"> remove </span></a></div> <strong ><a href="http://twitter.com/asdasd" style="color:#d02b55;">usuario 2</a></strong> usuario 2. <br /> <div id="follow2"><a href="#" class="follow" id="2"><span class="follow_b"> Follow </span></a></div> <div id="remove2" style="display:none"><span class="youfollowing_b"> You Following </span><a href="#" class="remove" id="2"><span class="remove_b"> remove </span></a></div>
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/asddas" style="color:#d02b55;"><?php echo $row1['nombre']; ?></a></strong>
<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++;
}?>