home *** CD-ROM | disk | FTP | other *** search
/ Practical Internet Web Designer 88 / PIWD88.iso / mac / contents / developer / tutorial_files / Pages88-89 / test.php < prev   
PHP Script  |  2003-10-29  |  2KB  |  97 lines

  1. <?php
  2.  
  3. //connect to the database
  4.  
  5. $conn = mysql_connect("localhost","root","pwd");
  6.  
  7. //choose the cms db
  8.  
  9. mysql_select_db("cms", $conn);
  10.  
  11. //query the database for a list of categories
  12.  
  13. $result = mysql_query("SELECT catID, catName, catDesc FROM tblCat", $conn);
  14.  
  15. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  16.  
  17.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  18.  
  19.  
  20.  
  21. <html>
  22.  
  23. <head>
  24.  
  25. <title>CMS Homepage</title>
  26.  
  27. <link rel="stylesheet" type="text/css" href="global.css" />
  28.  
  29. </head>
  30.  
  31.  
  32.  
  33. <body>
  34.  
  35. <div id="banner">
  36.  
  37. <p> </p>
  38.  
  39. </div>
  40.  
  41. <div id="navigation">
  42.  
  43. <ul class="main">
  44.  
  45. <?php
  46.  
  47. //the navigation menu
  48.  
  49. while ($row = mysql_fetch_array($result)) {
  50.  
  51.     print("<li><a href=\"articles.php?catID=" . $row[catID] . "\">" . $row[catName] . "</a></li>\n");
  52.  
  53. }
  54.  
  55. //if you are going to use the result a second time on the page you must do this to go back to the start.
  56.  
  57. mysql_data_seek($result,0);
  58.  
  59. ?>
  60.  
  61. </ul>
  62.  
  63. </div>
  64.  
  65. <div id="content">
  66.  
  67. <h1>Welcome</h1>
  68.  
  69. <p>Content on this site is organised into categories, please select a category of interest below or in the menu, to view content within that category.</p>
  70.  
  71. <?php
  72.  
  73. //the categories listed with descriptions in the main body of the page
  74.  
  75. while ($row = mysql_fetch_array($result)) {
  76.  
  77.     print("<p><a href=\"articles.php?catID=" . $row[catID] . "\">" . $row[catName] . "</a><br />\n");
  78.  
  79.     print($row[catDesc] . "</p>\n");
  80.  
  81. }
  82.  
  83. //you should close the connection when you are finished with it
  84.  
  85. mysql_close($conn);
  86.  
  87. ?>
  88.  
  89. </div>
  90.  
  91. </body>
  92.  
  93. </html>
  94.  
  95.  
  96.  
  97.