Return to Snippet

Revision: 33946
at October 15, 2010 02:28 by juanchifc


Initial Code
<?php
$twitter=$_POST['twitter'];

$encontrado=false;
$servidor="localhost";
$usuario="root";
$pass="";
$base_datos="db_amigos";

$conexion=mysql_connect($servidor, $usuario, $pass);
mysql_select_db("db_amigos", $conexion);
$result = mysql_query("SELECT nombre, movil, mail, twitter FROM amigos", $conexion);

if ($row = mysql_fetch_array($result)){
	while($row = mysql_fetch_array($result)){
		if(strcmp($row['twitter'],$twitter)==0){
			$encontrado=true;
			"<h1>Los datos de $twitter son los siguientes:</h1> <br />";
			echo "<table border = '1'> \n";
			echo "<tr> \n";
			echo "<td><b>Nombre</b></td> \n";
			echo "<td><b>Móvil</b></td> \n";
			echo "<td><b>Mail</b></td> \n";
			echo "</tr> \n";
			
			
			do{
				echo "<tr> \n";
			echo "<td>".$row["nombre"]."</td> \n";
			echo "<td>".$row["movil"]."</td>\n";
			echo "<td>".$row["mail"]."</td> \n";
			echo "</tr> \n";
			}while(($row = mysql_fetch_array($result))&& (strcmp($row['twitter'],$twitter)==0));
		}
		if(!encontrado){
			echo"No tienes ningún amigo con el usuario".$twitter;
		}
		}//while
}else {
	echo "¡ La base de datos está vacia !";
}
		
?>

Initial URL

                                

Initial Description
By using this snippet we can recover fields from a database by filtering these ones per a specific field.

Initial Title
Recover fields from a database by filtering per a specific field

Initial Tags
database, php, filter

Initial Language
PHP