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.

121 lines
3.7 KiB

  1. <?php // lookup
  2. // include our database configuration
  3. require(($category) ? "db.php3" : "cfg.php3");
  4. // connect to the database
  5. $connection = connect($host, $dbname);
  6. if($connection) {
  7. // set up the initial values
  8. $multiple = 0;
  9. // begin building the query string
  10. $query = "select * from contact";
  11. if($category || $name || $contact) {
  12. // append any qualifiers
  13. $query .= " where ";
  14. if($category) {
  15. $query .= "category = '$category'";
  16. $multiple++;
  17. }
  18. if($name) {
  19. if($multiple) $query .= " and ";
  20. switch($nameoption) {
  21. case "start";
  22. $query .= "upper(name) like upper('$name%')";
  23. break;
  24. case "contain";
  25. $query .= "upper(name) like upper('%$name%')";
  26. break;
  27. case "end";
  28. $query .= "upper(name) like upper('%$name')";
  29. break;
  30. }
  31. $multiple++;
  32. }
  33. if($contact) {
  34. if($multiple) $query .= " and ";
  35. switch($contactoption) {
  36. case "start";
  37. $query .= "upper(contact) like upper('$contact%')";
  38. break;
  39. case "contain";
  40. $query .= "upper(contact) like upper('%$contact%')";
  41. break;
  42. case "end";
  43. $query .= "upper(contact) like upper('%$contact')";
  44. break;
  45. }
  46. $multiple++;
  47. }
  48. }
  49. // append an order by clause
  50. $query .= " order by category, name, contact";
  51. $result = query($connection, $query);
  52. $count = numrows($result);
  53. if($count) {
  54. if($content == "mem_result")
  55. // print a summary of the result
  56. print("Your query returned ($count) results.\n<br><br>\n");
  57. // create the table for the results
  58. print("<table width=520 border=0 cellpadding=1 cellspacing=0>\n");
  59. for($row=0; $row < $count; $row++) {
  60. $data = fetch_object($result, $row);
  61. // create a category header
  62. if($data->category != $samecategory) {
  63. if($samecategory)
  64. print("<tr><td colspan=2>&nbsp </td></tr>\n");
  65. print("<tr class=header><th colspan=2>");
  66. print("$data->category</th></tr>\n");
  67. $rowshade = 0;
  68. $samecategory = $data->category;
  69. }
  70. // alternate bgcolors
  71. $shade = (($rowshade++ & 1) ? "dark" : "light");
  72. // first line
  73. print("<tr class=$shade><td>");
  74. if($data->name && $data->contact) {
  75. print("$data->name ($data->contact)");
  76. } else { print($data->name . $data->contact); }
  77. print("</td><td align=right>");
  78. print($data->phtyp1 . " &nbsp " . $data->phnum1);
  79. print("</td></tr>\n");
  80. // second line
  81. print("<tr class=$shade><td>");
  82. print($data->address);
  83. print("</td><td align=right>");
  84. print($data->phtyp2 . " &nbsp " . $data->phnum2);
  85. print("</td></tr>\n");
  86. // third line
  87. print("<tr class=$shade><td>");
  88. print("$data->city, $data->state. $data->zip");
  89. if($data->zipext) print("-" . $data->zipext);
  90. print("</td><td align=right>");
  91. print($data->phtyp3 . " &nbsp " . $data->phnum3);
  92. print("</td></tr>\n");
  93. }
  94. print("</table></div>\n");
  95. // append a "New Search" button
  96. if($content == "mem_result") {
  97. print("<div class=offset>\n");
  98. print("<a href=page.php3?content=$same>\n");
  99. print("<img src=\"btn.php3?label=New+Search\" ");
  100. print("alt=\"New Search\" border=0></a>\n</div>\n");
  101. }
  102. // release the database query result
  103. free_result($result);
  104. } else {
  105. print("<div class=intro>\n");
  106. print("Sorry, your query returned an empty result.<br>\n");
  107. print("</div>\n<div class=offset>\n<a href=page.php3?content=$same>\n");
  108. print("<img src=\"btn.php3?label=Try+Again\" ");
  109. print("alt=\"Try Again\" border=0></a>\n</div>\n");
  110. }
  111. // close the database connection
  112. // close($connection);
  113. } else {
  114. print("<div class=center><h1>Database Error<hr></h1>\n");
  115. print("<h2>Failed to connect to database: ");
  116. print($dbname . "</h2>\n</div>\n");
  117. }
  118. ?>