Código PHP:
<script language="JavaScript" type="text/javascript" src="ajax.js"></script>
<?php
include("header.php");
if (!isset($_SESSION['logueado_usuario'])) {
include ("login.php");
echo "<a href='registro.php'>Registrarse</a>" ;}
else {
$nombre =$_SESSION['logueado_nombre'];
$id_usuario=$_SESSION['logueado_id'];
?>
<link href="../Css/estilo.css" rel="stylesheet" type="text/css">
<?php
include("privados/config.php");
$registros=mysql_query("select * from usuarios WHERE id != '$id_usuario' ORDER BY id desc ", $conexion)or
die("Problemas en el select:".mysql_error());
$i=0;
while($reg=mysql_fetch_array($registros))
{ ?>
<img src="<?php echo "".$reg['imagen']. "";?>" /><br />
<?php
$consulta="select Estado from amigos where id_logueado='$id_usuario' and id_amigo='$reg[id]'";
$ejecuta=mysql_query($consulta) or die("Problemas en el select:".mysql_error());
$cantidad=mysql_num_rows($ejecuta);
$consulta1="select Estado from amigos where id_logueado='$reg[id]' and id_amigo='$id_usuario'";
$ejecuta1=mysql_query($consulta1) or die ("Problemas en el select:".mysql_error());
$cantidad1=mysql_num_rows($ejecuta1);
if($cantidad > 0)
{
$row = mysql_fetch_assoc($ejecuta);
switch($row['Estado'])
{
case 'pendiente':
echo '<div id="resultado"> include("consulta.php");</div><div class="amigos">Ya mandaste petición</div>';
echo $reg['nombre'];
break;
case 'aceptado':
echo '<a href="perfil.php?id='.$reg['id'].'">'.$reg['nombre'].'</a>';
break;
}
}
elseif($cantidad1 > 0)
{
$row1= mysql_fetch_assoc($ejecuta1);
switch($row1['Estado'])
{
case 'pendiente':
echo '<div class="amigos">
<form action="agregara.php" method="post">
<input type="hidden" name="id" value="'.$reg['id'].'">
<input type="hidden" name="accion" value="modificar">
<input type="submit" value="Aceptar petición">
</form>
</div>';
echo $reg['nombre'];
break;
case 'aceptado':
echo '<a href="perfil.php?id='.$reg['id'].'">'.$reg['nombre'].'</a>';
break;
}
}
else
{
echo '<div class="amigos">
<form name="nuevo_amigo" action=""
onsubmit="enviarDatosAmigo(); return false">
<input type="hidden" value="<?php echo $id_amigo;?>" name="id">
<input type="hidden" value="<?php echo $id_logueado;?>" name="logueado">
<input type="hidden" value="pendiente" name="estado">
<input type="submit" name="Submit" value="Agregar ami" />
</form>
</div>';
echo $reg['nombre'];
}
?>
<div id="consulta"></div>
<? } ?>
<?php } ?>
este es gente.php tiene el formulario.