Advertisement
Guest User

consulta sql

a guest
Apr 4th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="es">
  3. <head>
  4.   <meta charset="utf-8">
  5.   <meta name="viewport" content="width=device-width, initial-scale=1">
  6.   <title>Mostrar datos</title>
  7. </head>
  8. <?php
  9.   $dbhost="hostname";
  10.   $dbuser="user";
  11.   $dbpass="pass";
  12.   $db="dbname";
  13.   $conn = mysql_connect ($dbhost, $dbuser, $dbpass) or die ("Error al conectar don bd: $dbhost, $dbuser, $dbpass" . mysql_error());
  14.   mysql_select_db ($db);
  15.  
  16.   $sql="SELECT campo1, campo2, campo3
  17.  FROM tabla
  18.  WHERE condicion
  19.  ORDER BY campo1;";
  20.   $consulta=mysql_query($sql);
  21. ?>
  22. <body>
  23. <table>
  24. <thead>
  25. <tr>
  26. <th>campo1</th>
  27. <th>campo2</th>
  28. <th>campo3</th>
  29. </tr>
  30. </thead>
  31. <tbody>
  32. <?php
  33. while ($fila = mysql_fetch_assoc($consulta)) {
  34. echo "<tr><td>".$fila['campo1']."</td>
  35.      <td>".$fila['campo2']."</td>
  36.      <td>".$fila['campo3']."</td>
  37. </tr>";
  38. }
  39. ?>
  40. </tbody>
  41. <?
  42.   mysql_free_result($consulta);
  43.   mysql_close($conn);
  44. ?>
  45. </table>
  46. </body>
  47. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement