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

  1. <?php
  2.  
  3. $thisCat = $_GET['catID'];
  4.  
  5. //connect to the database
  6.  
  7. $conn = mysql_connect("localhost","root","pwd");
  8.  
  9. //choose the cms db
  10.  
  11. mysql_select_db("cms", $conn);
  12.  
  13. //query the database for a list of the content for this category
  14.  
  15. $content = mysql_query("SELECT contentID, contentTitle,contentText FROM tblContent WHERE catID = " . $thisCat, $conn);
  16.  
  17. //query the database for a list of categories - for the navigation menu
  18.  
  19. $result = mysql_query("SELECT catID, catName, catDesc FROM tblCat", $conn);
  20.  
  21. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  22.  
  23.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  24.  
  25.  
  26.  
  27. <html>
  28.  
  29. <head>
  30.  
  31. <title>Articles</title>
  32.  
  33. <link rel="stylesheet" type="text/css" href="global.css" />
  34.  
  35. </head>
  36.  
  37.  
  38.  
  39. <body>
  40.  
  41. <div id="banner">
  42.  
  43. <p> </p>
  44.  
  45. </div>
  46.  
  47. <div id="navigation">
  48.  
  49. <ul class="main">
  50.  
  51. <?php
  52.  
  53. //the navigation menu
  54.  
  55. while ($row = mysql_fetch_array($result)) {
  56.  
  57.     print("<li><a href=\"articles.php?catID=" . $row[catID] . "\">" . $row[catName] . "</a></li>\n");
  58.  
  59. }
  60.  
  61. ?>
  62.  
  63. </ul>
  64.  
  65. </div>
  66.  
  67. <div id="content">
  68.  
  69. <?php
  70.  
  71. while ($contentrow = mysql_fetch_array($content)) {
  72.  
  73.  
  74.  
  75.     $arrayDesc = explode(" ", $contentrow[contentText]);
  76.  
  77.     $shortDesc = "";
  78.  
  79.     for($i=0 ; $i<30 ; $i++) {
  80.  
  81.         $shortDesc = $shortDesc . " " . $arrayDesc[$i];
  82.  
  83.     }
  84.  
  85.     
  86.  
  87.     print("<p><a href=\"showarticle.php?aID=" . $contentrow[contentID] . "\">" . $contentrow[contentTitle] . "</a><br />\n");
  88.  
  89.     print($shortDesc . "</p>\n");
  90.  
  91. }
  92.  
  93. //you should close the connection when you are finished with it
  94.  
  95. mysql_close($conn);
  96.  
  97. ?>
  98.  
  99.  
  100.  
  101. </div>
  102.  
  103. </body>
  104.  
  105. </html>
  106.  
  107.  
  108.  
  109.