Recover fields from a database


/ Published in: PHP
Save to your folder(s)

By using this snippnet we can recover and show on a table the items stored into a sql database managed with mysql.


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. $servidor="localhost";
  4. $usuario="root";
  5. $pass="";
  6. $base_datos="db_amigos";
  7.  
  8. $link=mysql_connect($servidor, $usuario, $pass);
  9. mysql_select_db("db_amigos", $link);
  10. $result = mysql_query("SELECT nombre, movil, mail, twitter FROM amigos", $link);
  11.  
  12. if ($row = mysql_fetch_array($result)){
  13.  
  14. echo "<table border = '1'> \n";
  15. echo "<tr> \n";
  16. echo "<td><b>Nombre</b></td> \n";
  17. echo "<td><b>Móvil</b></td> \n";
  18. echo "<td><b>Mail</b></td> \n";
  19. echo "<td><b>Twitter</b></td> \n";
  20. echo "</tr> \n";
  21.  
  22. do {
  23.  
  24. echo "<tr> \n";
  25. echo "<td>".$row["nombre"]."</td> \n";
  26. echo "<td>".$row["movil"]."</td>\n";
  27. echo "<td>".$row["mail"]."</td> \n";
  28. echo "<td>".$row["twitter"]."</td>\n";
  29. echo "</tr> \n";
  30.  
  31. } while ($row = mysql_fetch_array($result));
  32.  
  33. echo "</table> \n";
  34. } else {
  35.  
  36. echo "¡ La base de datos está vacia !";
  37. }
  38.  
  39. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.