function get_shots($dbc, $slug) { $queryString = generate_query($slug, 20, 0); $stmt = $dbc->prepare("{$queryString}"); $stmt->execute(); $data = $stmt->fetchAll(); return $data; }
// a string with filtering if the user wants to filter their search. $query_text = "SELECT cubeID, cubeNumber, cubicle.personID, loclat, loclong, email, phone, Department.deptName, firstName, lastName, iconPath FROM cubicle natural join Personnel natural join Department natural join Icons WHERE"; // Split the text in the search boxes by ","'s. This is if they want to search for // multiple items. $exploded_string = explode(",", $search_text); // If they there is a "," in the search term, they want to search for multiple items. if (count($exploded_string) > 1) { for ($i = 0; $i < count($exploded_string); $i++) { $query_text = generate_query($query_text, $exploded_string[$i], $filter); if ($i < count($exploded_string) - 1) { $query_text .= " OR"; } } } else { // Otherwise, just search for 1 item. $query_text = generate_query($query_text, $search_text, $filter); } // Select results that match our search fields from the database. $results_query = sqlite_query($db, $query_text); // Display the search results by echoing back HTML to the AJAX/Javascript // which will display the results to the user in plain text. if (sqlite_num_rows($results_query) > 0) { while ($results_row = @sqlite_fetch_array($results_query, SQLITE_ASSOC)) { echo "<p id=\"search_result\"><strong>"; echo $results_row['firstName']; echo " "; echo $results_row['lastName']; echo "</strong><br />"; echo "Dept: " . $results_row['Department.deptName']; echo "<br />"; echo "Office: " . $results_row['cubeNumber'];
// Open the SQLite database $db = new SQLITE3('SQLiteDB/OfficeLayout.db', SQLITE3_OPEN_READONLY); if (!$db) { die('Database could not be accessed.'); } // Grab the variables that were posted through AJAX. $search_text = $_REQUEST['search_text']; $filter = $_REQUEST['filter']; // Initial SELECT query string without any filtering. This will be concatenated // with filtering constraints if the user has selected any. $query_text = "SELECT EmployeeID, CubicleNumber, FirstName, LastName, DeptName, Email, Phone FROM Personnel WHERE"; // Split the text in the search boxes by commas. // This is in case the user wishes to search for multiple items. $exploded_string = explode(",", $search_text); for ($i = 0; $i < count($exploded_string); $i++) { $query_text = generate_query($query_text, $db->escapeString($exploded_string[$i]), $filter); if ($i < count($exploded_string) - 1) { $query_text .= " OR"; } } // Query the database for all matches with our search constraints. $statement = $db->prepare($query_text); $results = $statement->execute(); $have_result = false; // Display the search results by echoing back HTML to the AJAX/Javascript, // which will display the results to the user in plain text. while ($results_row = $results->fetchArray(SQLITE3_ASSOC)) { $have_result = true; echo "<p id=\"search_result\"><strong>"; echo $results_row['FirstName']; echo " ";