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

  1. <?php
  2. $thisCat = $_GET['catID'];
  3. //connect to the database
  4. $conn = mysql_connect("localhost","root","pwd");
  5. //choose the cms db
  6. mysql_select_db("cms", $conn);
  7. //query the database for a list of the content for this category
  8. $content = mysql_query("SELECT contentID, contentTitle,contentText FROM tblContent WHERE catID = " . $thisCat, $conn);
  9. //query the database for a list of categories - for the navigation menu
  10. $result = mysql_query("SELECT catID, catName, catDesc FROM tblCat", $conn);
  11. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  12.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  13.  
  14. <html>
  15. <head>
  16. <title>Articles</title>
  17. <link rel="stylesheet" type="text/css" href="global.css" />
  18. </head>
  19.  
  20. <body>
  21. <div id="banner">
  22. <p> </p>
  23. </div>
  24. <div id="navigation">
  25. <ul class="main">
  26. <?php
  27. //the navigation menu
  28. while ($row = mysql_fetch_array($result)) {
  29.     print("<li><a href=\"articles.php?catID=" . $row[catID] . "\">" . $row[catName] . "</a></li>\n");
  30. }
  31. ?>
  32. </ul>
  33. </div>
  34. <div id="content">
  35. <?php
  36. while ($contentrow = mysql_fetch_array($content)) {
  37.  
  38.     $arrayDesc = explode(" ", $contentrow[contentText]);
  39.     $shortDesc = "";
  40.     for($i=0 ; $i<30 ; $i++) {
  41.         $shortDesc = $shortDesc . " " . $arrayDesc[$i];
  42.     }
  43.     
  44.     print("<p><a href=\"showarticle.php?aID=" . $contentrow[contentID] . "\">" . $contentrow[contentTitle] . "</a><br />\n");
  45.     print($shortDesc . "</p>\n");
  46. }
  47. //you should close the connection when you are finished with it
  48. mysql_close($conn);
  49. ?>
  50.  
  51. </div>
  52. </body>
  53. </html>
  54.  
  55.