Posted By

JonnySnip3r on 04/08/11


Tagged

database simple quick easy procedural


Versions (?)

Simple database script


 / Published in: PHP
 

Just a simple database script.

  1. <?php
  2. // Connect to the server::
  3. mysql_connect('localhost','jonno','password')
  4. or die('Sorry, an error occurred when connecting to the server.');
  5.  
  6. // Select the database::
  7. mysql_select_db('carl_forum')
  8. or die ('Sorry, an error occurred when select the database.');
  9.  
  10. // Set uo our sql statement::
  11. $sql = "SELECT * FROM posts ORDER BY post_id DESC";
  12. ?>
  13.  
  14. <html>
  15. <head>
  16. <title>Carl's Forum</title>
  17. </head>
  18.  
  19. <body>
  20. <?php
  21.  
  22. $query = mysql_query($sql);
  23. while($row = mysql_fetch_array($query))
  24. {
  25. // Place the title_post inside a header 1 tag, so it looks nice and big::
  26. echo '<h1>' . $row['post_title'] . '</h1>';
  27.  
  28. // Now place the post_body inside some paragraph tags so they look nice::
  29. echo '<p>' . $row['post_body'] . '</p>';
  30. }
  31.  
  32. ?>
  33. </body>
  34. </html>

Report this snippet  

You need to login to post a comment.