Olive Branch MS Chamber of Commerce (circa Oct 1999)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

120 lines
3.6 KiB

  1. <?php // process the query data passed to us
  2. header("Pragma: no-cache");
  3. header("Content-type: text/html");
  4. $basetarget="main";
  5. include("html/head.std");
  6. include("config/db.config");
  7. include("config/db.functions." . $dbserver);
  8. //
  9. // connect to the database
  10. $connection = connect($host, $dbname);
  11. if($connection) {
  12. // set up the initial values
  13. $multiple = 0;
  14. // begin building the query string
  15. $query = "select $columns from $table";
  16. if($category || $name || $contact) {
  17. // append any qualifiers
  18. $query .= " where ";
  19. if($category) {
  20. $query .= "category = '" . $category . "'";
  21. $multiple++;
  22. }
  23. if($name) {
  24. if($multiple) $query .= " and ";
  25. switch($nameoption) {
  26. case "start";
  27. $query .= "upper(name) like upper('" . $name . "%')";
  28. break;
  29. case "contain";
  30. $query .= "upper(name) like upper('%" . $name . "%')";
  31. break;
  32. case "end";
  33. $query .= "upper(name) like upper('%" . $name . "')";
  34. break;
  35. }
  36. $multiple++;
  37. }
  38. if($contact) {
  39. if($multiple) $query .= " and ";
  40. switch($contactoption) {
  41. case "start";
  42. $query .= "upper(contact) like upper('" . $contact . "%')";
  43. break;
  44. case "contain";
  45. $query .= "upper(contact) like upper('%" . $contact . "%')";
  46. break;
  47. case "end";
  48. $query .= "upper(contact) like upper('%" . $contact . "')";
  49. break;
  50. }
  51. $multiple++;
  52. }
  53. }
  54. // append an order by clause
  55. $query .= " order by category, name, contact";
  56. //
  57. // print("<p><b>query:</b> " . $query . "<br>\n");
  58. //
  59. $result = query($connection, $query);
  60. $total_rows = numrows($result);
  61. if($total_rows) {
  62. // create the table for the results
  63. print("<table width=580 border=0 cellpadding=0 cellspacing=0>\n");
  64. for($row=0; $row < $total_rows; $row++) {
  65. $data = fetch_object($result, $row);
  66. print("<tbody>\n");
  67. // create a category header
  68. if($data->category != $samecategory) {
  69. if(isset($samecategory))
  70. print("<tr><td colspan=2>&nbsp </td></tr>\n");
  71. print("<tr class=header><th colspan=2>");
  72. print($data->category . "</th></tr>\n");
  73. $rowshade = 0;
  74. $samecategory = $data->category;
  75. }
  76. // alternate bgcolors
  77. $shade = (($rowshade++ & 1) ? "dark" : "light");
  78. // first line
  79. print("<tr class=" . $shade . "><td>");
  80. if($data->name && $data->contact) {
  81. print($data->name . " (" . $data->contact . ")");
  82. } else { print($data->name . $data->contact); }
  83. print("</td><td align=right>");
  84. print($data->phtyp1 . "&nbsp " . $data->phnum1);
  85. print("</td></tr>\n");
  86. // second line
  87. print("<tr class=" . $shade . "><td>");
  88. print($data->address);
  89. print("</td><td align=right>");
  90. print($data->phtyp2 . "&nbsp " . $data->phnum2);
  91. print("</td></tr>\n");
  92. // third line
  93. print("<tr class=" . $shade . "><td>");
  94. print($data->city . ", " . $data->state . ". " . $data->zip);
  95. if($data->zipext) { print("-" . $data->zipext); }
  96. print("</td><td align=right>");
  97. print($data->phtyp3 . "&nbsp " . $data->phnum3);
  98. print("</td></tr>\n");
  99. print("</tbody>\n");
  100. }
  101. print("</table>\n");
  102. // release the database query result
  103. free_result($result);
  104. } else {
  105. print("<h1 class=center>Empty Result<hr></h1>\n");
  106. print("<h2>The following query returned an empty result:</h2>\n");
  107. print("<p class=center>" . $query . "\n");
  108. }
  109. // close the database connection
  110. close($connection);
  111. } else {
  112. print("<h1 class=center>Database Error<hr></h1>\n");
  113. print("<h2 class=center>Failed to connect to database: ");
  114. print($dbname . "</h2>\n");
  115. }
  116. // close up the html tags
  117. include("html/tail.std");
  118. ?>