Posted By

juanchifc on 10/15/10


Tagged

database php filter set field recover


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

bobbym245
koyotebr


Recover fields from a database by filtering per a specific field


 / Published in: PHP
 

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

  1. <?php
  2. $twitter=$_POST['twitter'];
  3.  
  4. $encontrado=false;
  5. $servidor="localhost";
  6. $usuario="root";
  7. $pass="";
  8. $base_datos="db_amigos";
  9.  
  10. $conexion=mysql_connect($servidor, $usuario, $pass);
  11. mysql_select_db("db_amigos", $conexion);
  12. $result = mysql_query("SELECT nombre, movil, mail, twitter FROM amigos", $conexion);
  13.  
  14. if ($row = mysql_fetch_array($result)){
  15. while($row = mysql_fetch_array($result)){
  16. if(strcmp($row['twitter'],$twitter)==0){
  17. $encontrado=true;
  18. "<h1>Los datos de $twitter son los siguientes:</h1> <br />";
  19. echo "<table border = '1'> \n";
  20. echo "<tr> \n";
  21. echo "<td><b>Nombre</b></td> \n";
  22. echo "<td><b>Móvil</b></td> \n";
  23. echo "<td><b>Mail</b></td> \n";
  24. echo "</tr> \n";
  25.  
  26.  
  27. do{
  28. echo "<tr> \n";
  29. echo "<td>".$row["nombre"]."</td> \n";
  30. echo "<td>".$row["movil"]."</td>\n";
  31. echo "<td>".$row["mail"]."</td> \n";
  32. echo "</tr> \n";
  33. }while(($row = mysql_fetch_array($result))&& (strcmp($row['twitter'],$twitter)==0));
  34. }
  35. if(!encontrado){
  36. echo"No tienes ningún amigo con el usuario".$twitter;
  37. }
  38. }//while
  39. }else {
  40. echo "¡ La base de datos está vacia !";
  41. }
  42.  
  43. ?>

Report this snippet  

You need to login to post a comment.