1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4. <head>
5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
6. <title>View My Blog</title>
7. </head>
8. <body>
9. <h1>My Blog</h1>
10. <?php // Script 12.7 - view_blog.php
11. /* This script retrieves blog entries from the database. */
12.
13. // Connect and select:
14. $dbc = mysql_connect('h41mysql35.secureserver.net', 'yrosenthal', 'Password.1');
15. mysql_select_db('yrosenthal');
16.
17. // Define the query:
18. $query = 'SELECT * FROM entries ORDER BY date_entered DESC';
19.
20. if ($r = mysql_query($query)) { // Run the query.
21.
22. // Retrieve and print every record:
23. while ($row = mysql_fetch_array($r)) {
24. print "<p><h3>{$row['title']}</h3>
25. {$row['entry']}<br />
26. <a href=\"script_12_09.php?id={$row['entry_id']}\">Edit</a>
27. <a href=\"script_12_08?id={$row['entry_id']}\">Delete</a>
28. </p><hr />\n";
29. }
30.
31. } else { // Query didn't run.
32. print '<p style="color: red;">Could not retrieve the data because:<br />' . mysql_error() . '.</p><p>The query being run was: ' . $query . '</p>';
33. } // End of query IF.
34.
35. mysql_close(); // Close the database connection.
36.
37. ?>
38. </body>
39. </html>