Search Page
From Jay's Cafe' Wiki
<?php $servername = "192.168.2.12"; $username = "wp_teda.org"; $password = "wp_teda.org"; $dbname = "db_medical_resources"; $rec_limit = 10; ?> <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method='post'>What are you looking for? <br><em>Less is more. If you don't find what you are looking for, try just a few letters of the name.</em><br> <table class="search_form" style="border-style: none; "> <tr> <td class="search_select" style="border-style: none;" colspan="2" > <input type="text" name="search_terms" size="60" maxlength="160" class="search_select"> </td> <td class="search_select"> <button name="submit" value="Submit" type="submit">Search</button> </td></tr> <tr> <td class="search_select">Highlighting the parish will limit the results to that parish.</td> <td align="right" class="search_select" style="border-style: none;" > <select name="sel_parish" size="3"> <option value="terrebonne">Terrebonne</option> <option value="lafourche">Lafourche</option> <option value="assumption">Assumption</option> </select> </td></tr> <tr><td class="search_select"> </td></tr> </table> </form> <?php $search_selected_field = 'fld_Name'; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $search_selected_field = $_POST["search_select"] ; $search_terms = $_POST["search_terms"]; $parish = $_POST["sel_parish"]; if (!empty($parish)) { $sql = 'select * from tbl_Flat_Resources where ( ( ( fld_ServicesDescription like "%' . $search_terms . '%" ) or ( fld_Name like "%' . $search_terms . '%") or ( fld_InsurancePlans like "%' . $search_terms . '%") or ( fld_WebAddress like "%' . $search_terms . '%") or ( fld_Designation like "%' . $search_terms . '%") or ( fld_Location like "%' . $search_terms . '%") or ( fld_AddressCity like "%' . $search_terms . '%") ) AND ( fld_Parish like "%' . $parish . '%") );'; } else { $sql = 'select * from tbl_Flat_Resources where ( ( ( fld_ServicesDescription like "%' . $search_terms . '%" ) or ( fld_Name like "%' . $search_terms . '%") or ( fld_InsurancePlans like "%' . $search_terms . '%") or ( fld_WebAddress like "%' . $search_terms . '%") or ( fld_Designation like "%' . $search_terms . '%") or ( fld_Location like "%' . $search_terms . '%") or ( fld_AddressCity like "%' . $search_terms . '%") ) );'; } // $sql = "select * from tbl_Flat_Resources;"; // echo $sql; $result = $conn->query($sql); echo "<br />"; $numrows = mysqli_num_rows($result); echo "You have found " . mysqli_num_rows($result) . " results.<p />"; if ($numrows > 0) { ?> <!-- Results Table Display --> <table class="search_select"> <?php // output data of each row while($row = $result->fetch_assoc()) { echo "<tr><td >" . $row["fld_Name"] . "</td></tr> "; // determine row break // $rowbreak = fmod($x, $y); // if((int)fmod($numrows, '3');) { echo "<tr/><tr>" } ?> </table> <?php } else { echo "0 results"; } $conn->close(); ?>