Last active
August 29, 2015 14:15
-
-
Save jsstoni/5feb46a8c94b4b7322ab to your computer and use it in GitHub Desktop.
Creando sistema de seguir usuarios
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Id_Usuario: se refiere al usuario el cual se encuentra activo */ | |
/* Id_seguir: este seria el id del usuario el cual se a seguido */ | |
CREATE TABLE seguidores | |
( | |
Id_Usuario int, | |
Id_seguir int | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//session_start(); | |
//instaciar el objecto para conectar a la base de datos mysql | |
$sql = new mysqli(server, usuario, password, db); | |
//variable de session del usuario $_SESSION['usuario'] = 1; | |
$id_SessionUsuario = 1; | |
//variable al id a cual seguir o dejar de seguir | |
$id_seguir = $_GET['seguir']; | |
//se verifica el id a seguir | |
$r = $sql->query("SELECT * FROM seguidores WHERE Id_seguir = $id_seguir"); | |
//si la consulta $r es mayor que 0 se refiere que esta ya registrado el seguimiento | |
if ($r->num_rows > 0) { | |
//se borra el siguimiento | |
$r = $sql->query("DELETE FROM seguidores WHERE Id_Usuario = $id_SessionUsuario AND Id_seguir = $id_seguir"); | |
//retorna 0 para verificar que lo a dejado de seguir | |
return 0; | |
}else { | |
//si no existe ningun seguimiento se inserta para seguir | |
$r = $sql->query("INSERT INTO seguidores (Id_Usuario, Id_seguir) VALUES ('$id_SessionUsuario', '$id_seguir')"); | |
//retorna 1 para verificar que esta siguiendo | |
return 1; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment